swagger-ui转化为pdf/html文件,然后再转化为word文档格式

1.首先maven依赖中,添加swagger2Markup依赖坐标

   <dependency>
       <groupId>io.github.swagger2markup</groupId>
       <artifactId>swagger2markup</artifactId>
       <version>1.3.1</version>
   </dependency>

2 .然后在maven中添加插件,注意要改端口号

   <plugin>
       <groupId>io.github.swagger2markup</groupId>
       <artifactId>swagger2markup-maven-plugin</artifactId>
       <version>1.2.0</version>
       <configuration>
           <!--此处端口一定要是当前项目启动所用的端口-->
           <swaggerInput>http://localhost:8086/v2/api-docs</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>

3 .接着就可以在编译器的terminal中运行以下命令

mvn swagger2markup:convertSwagger2markup
mvn generate-resources

此时进入新生成的文件夹中就可以看到paths.html文件
在这里插入图片描述
4 . 将此文件使用word打开方式打开,直接另存为选择word格式便可
在这里插入图片描述
至此为止,便可以得到一个word接口文档,只需修正便可

tips:
中间参考了一个大佬的文章
https://blog.csdn.net/qq_16256793/article/details/79522749

发布了11 篇原创文章 · 获赞 2 · 访问量 338

猜你喜欢

转载自blog.csdn.net/weixin_45121502/article/details/104962738