Swagger接口导出word、pdf文档

2 篇文章 0 订阅

swagger接口文档导出为word、pdf文档有几种方式

1. 在线转换

在线swagger转word文档|swagger导出word文档 - Kalvin在线工具

把swagger中的json串导入到此网站就行

2. maven插件转换

新建一个maven工程;

pom代码如下:

 <dependencies>
        <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.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.github.swagger2markup</groupId>
                <artifactId>swagger2markup-maven-plugin</artifactId>
                <version>1.2.0</version>
                <configuration>
                    <!--此处端口一定要是当前项目启动所用的端口-->
                    <swaggerInput>C:\Users\huangqingwen\Desktop\swagger.json</swaggerInput>
                    <outputDir>src/docs/asciidoc/generated</outputDir>
                    <config>
                        <!-- 除了ASCIIDOC之外,还有MARKDOWN和CONFLUENCE_MARKUP可选 -->
                        <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
                    </config>
                </configuration>
            </plugin>

            <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>
        </plugins>
    </build>

然后执行maven命令:

mvn swagger2markup:convertSwagger2markup
mvn generate-resources

然后就会在对应的目录下生成word、pdf文件

 

注意:maven插件中asciidoctor导出pdf的时候中文会可能缺失,原因可能是因为该插件的作者是外国的,没有怎么适配到中文,所以大家如果想要pdf的话可以配置一下字体;又或者用word文档,word文档是不会缺失中文的,最后再用word文档转换成pdf。

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
Swagger导出接口文档可以通过将Swagger的json文件转换成不同格式的文档。首先需要获取Swagger的json文件,可以通过访问http://localhost:8080/v2/api-docs来获取,或者通过浏览器的开发者工具(F12控制台)获取响应的json信息。\[1\] 接下来,可以使用在线工具将json文件转换成DOC格式的文档。也可以使用转换网站DOCWAY将json文件导入项目后进行转换成PDF或MARKDOWN格式的文档。\[1\] 如果想要使用pom依赖来导出PDF或HTML格式的文档,可以在pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>io.github.swagger2markup</groupId> <artifactId>swagger2markup</artifactId> <version>1.3.1</version> </dependency> ``` 同时,还可以使用pom插件依赖来实现导出接口文档的功能。\[2\] 总结起来,Swagger导出接口文档的步骤包括获取Swagger的json文件,将json文件转换成不同格式的文档,或者使用pom依赖和插件来实现导出功能。 #### 引用[.reference_title] - *1* [Swagger导出离线文档 接口文档](https://blog.csdn.net/weixin_44339617/article/details/126439273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [swagger导出接口文档](https://blog.csdn.net/L_994572281_LYA/article/details/122408337)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值