class GenerateUtil {

  static void generateDocument(String contractLocation, String documentOutput, String type) throws IOException {

    // TODO: support users to addParamCtx other getGenerator type soon
    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);
      }
    });
  }

}