zoukankan      html  css  js  c++  java
  • swagger2 导出api为html和word文档

    参考地址

    https://blog.csdn.net/zhuyu19911016520/article/details/85048271

    依赖引入

    <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.8.0</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>2.8.0</version>
            </dependency>
    
            <!-- ********************* swagger导出PDF/HTML所需依赖 START ********************************* -->
            <dependency>
                <groupId>io.github.swagger2markup</groupId>
                <artifactId>swagger2markup</artifactId>
                <version>1.3.1</version>
            </dependency>

    第二部分需要添加的是生成ASCIIDOC所需要maven插件:

    <!--此插件生成ASCIIDOC-->
                <plugin>
                    <groupId>io.github.swagger2markup</groupId>
                    <artifactId>swagger2markup-maven-plugin</artifactId>
                    <version>1.2.0</version>
                    <configuration>
                        <!--此处端口一定要是当前项目启动所用的端口-->
                        <swaggerInput>http://localhost:8082/v2/api-docs</swaggerInput>
                        <outputDir>src/docs/asciidoc/generated</outputDir>
                        <config>
                            <!-- 除了ASCIIDOC之外,还有MARKDOWN和CONFLUENCE_MARKUP可选 -->
                            <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
                        </config>
                    </configuration>
                </plugin>

    第三部分需要添加输出PDF和HTML的maven插件:

    <!--此插件生成HTML和PDF-->
                <plugin>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctor-maven-plugin</artifactId>
                    <version>1.5.3</version>
                    <!-- Include Asciidoctor PDF for pdf generation -->
                    <dependencies>
                        <dependency>
                            <groupId>org.asciidoctor</groupId>
                            <artifactId>asciidoctorj-pdf</artifactId>
                            <version>1.5.0-alpha.10.1</version>
                        </dependency>
                        <dependency>
                            <groupId>org.jruby</groupId>
                            <artifactId>jruby-complete</artifactId>
                            <version>1.7.21</version>
                        </dependency>
                    </dependencies>
                    <!-- Configure generic document generation settings -->
                    <configuration>
                        <sourceDirectory>src/docs/asciidoc/generated</sourceDirectory>
                        <sourceHighlighter>coderay</sourceHighlighter>
                        <attributes>
                            <toc>left</toc>
                        </attributes>
                    </configuration>
                    <!-- Since each execution can only handle one backend, run
                         separate executions for each desired output type -->
                    <executions>
                        <execution>
                            <id>output-html</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>process-asciidoc</goal>
                            </goals>
                            <configuration>
                                <backend>html5</backend>
                                <outputDirectory>src/docs/asciidoc/html</outputDirectory>
                            </configuration>
                        </execution>
    
                        <execution>
                            <id>output-pdf</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>process-asciidoc</goal>
                            </goals>
                            <configuration>
                                <backend>pdf</backend>
                                <outputDirectory>src/docs/asciidoc/pdf</outputDirectory>
                            </configuration>
                        </execution>
    
                    </executions>
                </plugin>

    最后执行命令

    1.mvn swagger2markup:convertSwagger2markup

    2.mvn generate-resources

  • 相关阅读:
    1、常见ELK架构工作流程
    centos7系统zabbix 4.4版本升级到5.0版本
    K3s简介(一)
    三、saltstack数据系统grains
    爬取猫眼电影top100信息
    第一次爬虫实例
    docker容器轻量级web管理工具之portainer(六)
    liunx添加swap分区
    iptables 配置详解
    几个比较经典的算法问题的java实现
  • 原文地址:https://www.cnblogs.com/james-roger/p/13183661.html
Copyright © 2011-2022 走看看