我的包管理是gradle
implementation 'io.github.swagger2markup:swagger2markup:1.3.1'
按照自己的包管理工具获取上述包依赖
在test文件夹:
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) public class DemoApplicationTests { @Test public void generateAsciiDocs() throws Exception { // 输出Ascii格式 Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withMarkupLanguage(MarkupLanguage.MARKDOWN) .build(); Swagger2MarkupConverter.from(new URL("http://localhost:8099/v2/api-docs")) .withConfig(config) .build() .toFolder(Paths.get("src/docs/markdown/generated")); } }
运行这个,将会在项目目录下生成markdownn格式的文档,具体内容可以参考:https://blog.csdn.net/fly910905/article/details/105504324,这里面讲的比较全面