Package com.hypnoticocelot.jaxrs.doclet

Examples of com.hypnoticocelot.jaxrs.doclet.Recorder


    private void writeApis(Collection<ApiDeclaration> apis) throws IOException {
        List<ResourceListingAPI> resources = new LinkedList<ResourceListingAPI>();
        File outputDirectory = options.getOutputDirectory();
        String swaggerUiZipPath = options.getSwaggerUiZipPath();
        Recorder recorder = options.getRecorder();
        for (ApiDeclaration api : apis) {
            String resourcePath = api.getResourcePath();
            if (!Strings.isNullOrEmpty(resourcePath)) {
                String resourceName = resourcePath.replaceFirst("/", "").replaceAll("/", "_").replaceAll("[\\{\\}]", "");
                resources.add(new ResourceListingAPI("/" + resourceName + ".{format}", ""));
                File apiFile = new File(outputDirectory, resourceName + ".json");
                recorder.record(apiFile, api);
            }
        }

        //write out json for api
        ResourceListing listing = new ResourceListing(options.getApiVersion(), options.getDocBasePath(), resources);
        File docFile = new File(outputDirectory, "service.json");
        recorder.record(docFile, listing);

        // Copy swagger-ui into the output directory.
        ZipInputStream swaggerZip;
        if (DocletOptions.DEFAULT_SWAGGER_UI_ZIP_PATH.equals(swaggerUiZipPath)) {
            swaggerZip = new ZipInputStream(ServiceDoclet.class.getResourceAsStream("/swagger-ui.zip"));
            System.out.println("Using default swagger-ui.zip file from SwaggerDoclet jar file");
        } else {
            if (new File(swaggerUiZipPath).exists()) {
                swaggerZip = new ZipInputStream(new FileInputStream(swaggerUiZipPath));
                System.out.println("Using swagger-ui.zip file from: " + swaggerUiZipPath);
            } else {
                File f = new File(".");
                System.out.println("SwaggerDoclet working directory: " + f.getAbsolutePath());
                System.out.println("-swaggerUiZipPath not set correct: " + swaggerUiZipPath);

                throw new RuntimeException("-swaggerUiZipPath not set correct, file not found: " + swaggerUiZipPath);
            }
        }
       
        ZipEntry entry = swaggerZip.getNextEntry();
        while (entry != null) {
            final File swaggerFile = new File(outputDirectory, entry.getName());
            if (entry.isDirectory()) {
                if (!swaggerFile.isDirectory() && !swaggerFile.mkdirs()) {
                    throw new RuntimeException("Unable to create directory: " + swaggerFile);
                }
            } else {
                recorder.record(swaggerFile, swaggerZip);
            }

            entry = swaggerZip.getNextEntry();
        }
        swaggerZip.close();
View Full Code Here

TOP

Related Classes of com.hypnoticocelot.jaxrs.doclet.Recorder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.