@Test public void testGenerateDocument() throws Exception { String contractLocation = this.testResourcesEx.getContractLocation(); String codeOutput = "target/GenerateUtilTest/document"; generateDocument(contractLocation, codeOutput, "default"); assertNotEquals(0, Objects.requireNonNull(new File(codeOutput).listFiles()).length); try { generateDocument(contractLocation, codeOutput, "invalidType"); fail("Run 'testGenerateDocument' failed, expected to occur RuntimeException but not"); } catch (RuntimeException e) { assertEquals("Cannot found document generator's implementation", e.getMessage()); } }
static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException { DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type); if (docGenerator == null) { throw new RuntimeException("Cannot found document generator's implementation"); } Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isDirectory(file)) { return super.visitFile(file, attrs); } Map<String, Object> docGeneratorConfig = new HashMap<>(); SwaggerParseResult swaggerParseResult = new OpenAPIParser() .readLocation(file.toUri().toURL().toString(), null, null); OpenAPI openAPI = swaggerParseResult.getOpenAPI(); if (openAPI == null) { return super.visitFile(file, attrs); } docGeneratorConfig.put("contractContent", openAPI); docGeneratorConfig.put("outputPath", documentOutput + File.separator + file.getParent().toFile().getName() + File.separator + file.toFile() .getName() .substring(0, file.toFile().getName().indexOf("."))); docGenerator.configure(docGeneratorConfig); docGenerator.generate(); return super.visitFile(file, attrs); } }); }
GenerateUtil { static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException { DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type); if (docGenerator == null) { throw new RuntimeException("Cannot found document generator's implementation"); } Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isDirectory(file)) { return super.visitFile(file, attrs); } Map<String, Object> docGeneratorConfig = new HashMap<>(); SwaggerParseResult swaggerParseResult = new OpenAPIParser() .readLocation(file.toUri().toURL().toString(), null, null); OpenAPI openAPI = swaggerParseResult.getOpenAPI(); if (openAPI == null) { return super.visitFile(file, attrs); } docGeneratorConfig.put("contractContent", openAPI); docGeneratorConfig.put("outputPath", documentOutput + File.separator + file.getParent().toFile().getName() + File.separator + file.toFile() .getName() .substring(0, file.toFile().getName().indexOf("."))); docGenerator.configure(docGeneratorConfig); docGenerator.generate(); return super.visitFile(file, attrs); } }); } }
GenerateUtil { static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException { DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type); if (docGenerator == null) { throw new RuntimeException("Cannot found document generator's implementation"); } Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isDirectory(file)) { return super.visitFile(file, attrs); } Map<String, Object> docGeneratorConfig = new HashMap<>(); SwaggerParseResult swaggerParseResult = new OpenAPIParser() .readLocation(file.toUri().toURL().toString(), null, null); OpenAPI openAPI = swaggerParseResult.getOpenAPI(); if (openAPI == null) { return super.visitFile(file, attrs); } docGeneratorConfig.put("contractContent", openAPI); docGeneratorConfig.put("outputPath", documentOutput + File.separator + file.getParent().toFile().getName() + File.separator + file.toFile() .getName() .substring(0, file.toFile().getName().indexOf("."))); docGenerator.configure(docGeneratorConfig); docGenerator.generate(); return super.visitFile(file, attrs); } }); }  }
GenerateUtil { static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException { DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type); if (docGenerator == null) { throw new RuntimeException("Cannot found document generator's implementation"); } Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isDirectory(file)) { return super.visitFile(file, attrs); } Map<String, Object> docGeneratorConfig = new HashMap<>(); SwaggerParseResult swaggerParseResult = new OpenAPIParser() .readLocation(file.toUri().toURL().toString(), null, null); OpenAPI openAPI = swaggerParseResult.getOpenAPI(); if (openAPI == null) { return super.visitFile(file, attrs); } docGeneratorConfig.put("contractContent", openAPI); docGeneratorConfig.put("outputPath", documentOutput + File.separator + file.getParent().toFile().getName() + File.separator + file.toFile() .getName() .substring(0, file.toFile().getName().indexOf("."))); docGenerator.configure(docGeneratorConfig); docGenerator.generate(); return super.visitFile(file, attrs); } }); }  static void generateContract(MavenProject project, String contractOutput, String contractFileType,
      String type); }
GenerateUtil { static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException { DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, type); if (docGenerator == null) { throw new RuntimeException("Cannot found document generator's implementation"); } Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Files.isDirectory(file)) { return super.visitFile(file, attrs); } Map<String, Object> docGeneratorConfig = new HashMap<>(); SwaggerParseResult swaggerParseResult = new OpenAPIParser() .readLocation(file.toUri().toURL().toString(), null, null); OpenAPI openAPI = swaggerParseResult.getOpenAPI(); if (openAPI == null) { return super.visitFile(file, attrs); } docGeneratorConfig.put("contractContent", openAPI); docGeneratorConfig.put("outputPath", documentOutput + File.separator + file.getParent().toFile().getName() + File.separator + file.toFile() .getName() .substring(0, file.toFile().getName().indexOf("."))); docGenerator.configure(docGeneratorConfig); docGenerator.generate(); return super.visitFile(file, attrs); } }); }  static void generateContract(MavenProject project, String contractOutput, String contractFileType,
      String type);  }