in cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java [61:108]
public void run() {
try {
Path specPath = Paths.get(specFile);
String[] fileName = new String[1];
DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, format);
Map<String, Object> docGeneratorConfig = new HashMap<>();
if (Files.isDirectory(specPath)) {
Files.walkFileTree(specPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
docGeneratorConfig.put("contractContent", parseOpenApi(specPath));
docGeneratorConfig.put("outputPath",
output + File.separator + file.toFile().getName().substring(0, file.toFile().getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
docGenerator.generate();
return super.visitFile(file, attrs);
}
});
} else if (Files.isRegularFile(specPath)) {
fileName[0] = specPath.toFile().getName();
docGeneratorConfig.put("contractContent", parseOpenApi(specPath));
docGeneratorConfig.put("outputPath", output + File.separator + new File(specFile).getName()
.substring(0, new File(specFile).getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
docGenerator.generate();
} else {
fileName[0] = specFile;
docGeneratorConfig.put("contractContent", parseOpenApi(specPath));
docGeneratorConfig.put("outputPath", output + File.separator + new File(specFile).getName()
.substring(0, new File(specFile).getName().indexOf(".")));
docGenerator.configure(docGeneratorConfig);
docGenerator.generate();
}
LOGGER.info("Success to generate document, the directory is: {}", output);
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
}