Java源码示例:io.github.robwin.markup.builder.MarkupLanguage
示例1
@After
public void Test() throws Exception {
// 得到swagger.json,写入outputDir目录中
mockMvc.perform(get("/v2/api-docs").accept(MediaType.APPLICATION_JSON))
.andDo(SwaggerResultHandler.outputDirectory(outputDir).build())
.andExpect(status().isOk())
.andReturn();
// 读取上一步生成的swagger.json转成asciiDoc,写入到outputDir
// 这个outputDir必须和插件里面<generated></generated>标签配置一致
Swagger2MarkupConverter.from(outputDir + "/swagger.json")
.withPathsGroupedBy(GroupBy.TAGS)// 按tag排序
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)// 格式
.withExamples(snippetDir)
.build()
.intoFolder(outputDir);// 输出
}
示例2
@Test
public void convertSwaggerToMarkdown() throws Exception {
this.mockMvc.perform(get("/v2/api-docs")
.accept(MediaType.APPLICATION_JSON))
.andDo(Swagger2MarkupResultHandler.outputDirectory("src/docs/markdown/generated")
.withMarkupLanguage(MarkupLanguage.MARKDOWN).build())
.andExpect(status().isOk());
}
示例3
@Test
@Ignore public void convertRemoteSwaggerToMarkdown() throws IOException {
// Remote Swagger source
// Markdown
Swagger2MarkupConverter.from("http://localhost:4024/api-docs").withMarkupLanguage(MarkupLanguage.MARKDOWN).build().intoFolder("src/docs/markdown/generated");
// Then validate that three Markdown files have been created
String[] files = new File("src/docs/markdown/generated").list();
assertTrue(Arrays.asList(files).contains("definitions.md"));
assertTrue(Arrays.asList(files).contains("overview.md"));
assertTrue(Arrays.asList(files).contains("paths.md"));
}
示例4
public static void convertSwaggerToMarkdown(final String swaggerJsonUrlString,
final String targetFolderPath)
throws IOException {
Swagger2MarkupConverter.from(swaggerJsonUrlString)
.withMarkupLanguage(MarkupLanguage.MARKDOWN)
.withPathsGroupedBy(GroupBy.TAGS)
.withDefinitionsOrderedBy(OrderBy.NATURAL)
.build()
.intoFolder(targetFolderPath);
}