maven配置

<!-- swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>RELEASE</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>RELEASE</version>
</dependency>
<dependency>
    <groupId>io.github.swagger2markup</groupId>
    <artifactId>markup-document-builder</artifactId>
    <version>RELEASE</version>
</dependency>
<dependency>
    <groupId>io.github.swagger2markup</groupId>
    <artifactId>swagger2markup</artifactId>
    <version>RELEASE</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>RELEASE</version>
</dependency>
<!--swagger 导出配置-->
<repository>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <id>jcenter-releases</id>
    <name>jcenter</name>
    <url>https://jcenter.bintray.com</url>
</repository>
<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>1.5.6</version>
    <configuration>
        <sourceDirectory>docs/asciidoc/generated</sourceDirectory>
        <outputDirectory>docs/asciidoc/html</outputDirectory>
        <backend>html</backend>
        <sourceHighlighter>coderay</sourceHighlighter>
        <attributes>
            <toc>left</toc>
        </attributes>
    </configuration>
</plugin>

写一个测试类生成文档:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class SwaggerTo {

    /**
     * 生成AsciiDocs格式文档,并汇总成一个文件
     *
     * @throws Exception
     */
    @Test
    public void generateAsciiDocsToFile() throws Exception {
        //    输出Ascii到单文件
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .build();

        Swagger2MarkupConverter.from(new URL("http://localhost:8080/v2/api-docs"))
                .withConfig(config)
                .build()
                .toFile(Paths.get("./docs/asciidoc/generated/all"));
    }
}

上面http://localhost:8080/v2/api-docs地址是下面红框内的地址

生成html格式的swagger文档

以上命令生成.doc文件 

以下命令可以把.doc文件转换成html文件

mvn asciidoctor:process-asciidoc 

参考文章:

https://www.cnblogs.com/yanqin/p/9145941.html

相关文章:

  • 2022-01-03
  • 2021-05-08
  • 2021-10-12
  • 2021-03-25
  • 2021-12-14
  • 2021-11-08
猜你喜欢
  • 2021-09-17
  • 2022-01-13
  • 2022-01-29
  • 2021-12-11
  • 2021-11-23
相关资源
相似解决方案