swagger-export是一个提供swagger文档导出功能的服务,不依赖于具体的API接口服务实现,你可以很方便地导出html和pdf两种格式的静态文档。源码来自swagger导出静态API文档工具,做了一些修改,以符合实际的项目需要。

一.在src下配置asciidoc

二.pom.xml

也就是maven插件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion> <groupId>com.jeesun</groupId>
<artifactId>swagger-export</artifactId>
<version>1.0.</version> <properties>
<swaggerInputPath>http://127.0.0.1:8080/api/v2/api-docs</swaggerInputPath>
</properties> <build>
<finalName>com-jeesun-${project.artifactId}-${project.version}</finalName> <plugins>
<!--此插件生成ASCIIDOC-->
<plugin>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup-maven-plugin</artifactId>
<version>1.3.</version>
<dependencies>
<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<version>1.3.</version>
</dependency>
</dependencies>
<configuration>
<!--此处端口一定要是当前项目启动所用的端口-->
<swaggerInput>${swaggerInputPath}</swaggerInput>
<outputDir>${project.build.directory}/docs/asciidoc/generated</outputDir>
<config>
<!-- 除了ASCIIDOC之外,还有MARKDOWN和CONFLUENCE_MARKUP可选 -->
<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
<swagger2markup.pathsGroupedBy>TAGS</swagger2markup.pathsGroupedBy>
<swagger2markup.outputLanguage>ZH</swagger2markup.outputLanguage>
</config>
</configuration>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>convertSwagger2markup</goal>
</goals>
</execution>
</executions> </plugin>
<!--此插件生成HTML和PDF-->
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.</version>
<!-- Include Asciidoctor PDF for pdf generation -->
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.-alpha.</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.jruby</groupId>-->
<!--<artifactId>jruby-complete</artifactId>-->
<!--<version>1.7.</version>-->
<!--</dependency>-->
<!-- Comment this section to use the default jruby artifact provided by the plugin -->
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>9.1.8.0</version>
</dependency>
<!-- Comment this section to use the default AsciidoctorJ artifact provided by the plugin -->
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>1.5.</version>
</dependency> </dependencies>
<!-- Configure generic document generation settings -->
<configuration>
<sourceDirectory>src/docs/asciidoc</sourceDirectory>
<sourceDocumentName>index.adoc</sourceDocumentName>
<sourceHighlighter>coderay</sourceHighlighter>
<attributes>
<doctype>book</doctype>
<toc>left</toc>
<toclevels></toclevels>
<numbered></numbered>
<hardbreaks></hardbreaks>
<sectlinks></sectlinks>
<sectanchors></sectanchors>
<generated>${project.build.directory}/docs/asciidoc/generated</generated>
</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>${project.build.directory}/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>${project.build.directory}/docs/asciidoc/pdf</outputDirectory>
</configuration>
</execution> </executions>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
<!--<repositories>
<repository>
<id>jcenter-releases</id>
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>-->
<pluginRepositories>
<pluginRepository>
<id>jcenter-releases</id>
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>
</project>

导出步骤

  1. 启动待导出的API接口服务;

  2. 修改pom文件中properties配置的swaggerInputPath值为目标服务的IP端口信息;

  3. 在当前目录执行mvn clean compile命令;

  4. 生成的文档有html和pdf两种格式,目录分别为

target\docs\asciidoc\html\index.html
target\docs\asciidoc\pdf\index.pdf

导出的pdf格式文件,中文存在显示问题。可用Word2016打开,然后另存为word格式文件。

注意:

导出时,如果有数据权限,得放出  /v2/api-docs 接口。

												

swagger的导出的更多相关文章

  1. 怎么将swagger API导出为HTML或者PDF

    文章目录 将swagger API导出为HTML或者PDF 什么是Asciidoc swagger2markup-maven-plugin asciidoctor-maven-plugin 使用命令行 ...

  2. 通过Swagger接口导出模板文件时报错:URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads.

    问题描述:通过Swagger接口导出Excel模板文件时,报错:URL.createObjectURL: Argument 1 is not valid for any of the 1-argume ...

  3. 在.Net Core WebAPI下给Swagger增加导出离线文档功能

    一丶前言 最近刚接触到Swagger,在github上下载了它的源码和demo学习了一遍,发现这个组件非常好用,不过不足的是它没有导出离线文档的功能,于是乎我就想给它加一个导出功能 Swagger G ...

  4. swagger json导出word,Typora软件推荐!!!

    场景: 前几天项目验收,赶了一整天补API接口设计文档,给爷整吐了.周末的时候就想能不能直接把swagger的json文件导出成word? 顺便学习一下NPOI的使用. 实现思路: 1.先把swaag ...

  5. swagger环境搭建

    下面所用工具下载   http://editor.swagger.io/#/  demo   一.安装 swagger editor   说明:安装swagger前需要安装node工具   工具安装 ...

  6. 浅谈API网关(API Gateway)如何承载API经济生态链

    序言 API经济生态链已经在全球范围覆盖, 绝大多数企业都已经走在数字化转型的道路上,API成为企业连接业务的核心载体, 并产生巨大的盈利空间.快速增长的API规模以及调用量,使得企业IT在架构上.模 ...

  7. 阿里云高磊:API网关加速能力聚合与生态集成

    导读:本文中,阿里云高级技术专家高磊(花名:埃兰)将聚焦API网关加速能力聚合与生态集成,讲述API如何实现系统间的衔接和API网关的产品升级进程,重点展示了一些新功能.新体验和新变化. 大家下午好, ...

  8. Swagger 导出API

    Swagger 导出API 这算是在博客园的第一篇博客吧,之后发的应该也会同步到博客园上. 此前的博客地址: https://blog.mytyiluo.cn Swagger简介 Swagger是一个 ...

  9. C#中缓存的使用 ajax请求基于restFul的WebApi(post、get、delete、put) 让 .NET 更方便的导入导出 Excel .net core api +swagger(一个简单的入门demo 使用codefirst+mysql) C# 位运算详解 c# 交错数组 c# 数组协变 C# 添加Excel表单控件(Form Controls) C#串口通信程序

    C#中缓存的使用   缓存的概念及优缺点在这里就不多做介绍,主要介绍一下使用的方法. 1.在ASP.NET中页面缓存的使用方法简单,只需要在aspx页的顶部加上一句声明即可:  <%@ Outp ...

随机推荐

  1. PHP quotemeta() 函数

    实例 在预定义的字符前添加反斜杠: <?php高佣联盟 www.cgewang.com$str = "Hello world. (can you hear me?)";ech ...

  2. HDU Typewriter 6583 dp SAM 卡常

    LINK:Typewriter 好久没写SAM了 什么都给忘了. 写了大概2h.感觉被卡常还看了题解. 考虑dp 然后容易想到维护前面的一个j决策 尽可能小. 然后每次考虑向后加一个字符 不过不行就跳 ...

  3. 入门实践,Python数据分析

    1-2 Anaconda和Jupyter notebook介绍 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知 ...

  4. 「查缺补漏」巩固你的Redis知识体系

    Windows Redis 安装 链接: https://pan.baidu.com/s/1MJnzX_qRuNXJI09euzkPGA 提取码: 2c6w 复制这段内容后打开百度网盘手机App,操作 ...

  5. Druid数据源的使用

    1 Druid数据源简介 Druid是Java语言中最好的数据库连接池.Druid能够提供强大的监控和扩展功能.通过访问http://localhost:8080(自己的端口)/druid/ 可以查看 ...

  6. JS DOM笔记

    js的组成     ECMAScript:JS的语法     DOM:页面文档对象模型     BOM:浏览器对象模型     web APIs     是浏览器提供的一套操作浏览器功能和页面元素的A ...

  7. MixNet:MixConv:Mixed Depthwise Convolution kernels

  8. [机器学习] keras:MNIST手写数字体识别(DeepLearning 的 HelloWord程序)

    深度学习界的Hello Word程序:MNIST手写数字体识别 learn from(仍然是李宏毅老师<机器学习>课程):http://speech.ee.ntu.edu.tw/~tlka ...

  9. 2020-06-02:千万级数据量的list找一个数据。

    福哥答案2020-06-02: 对于千万级长度的数组单值查找:序号小的,单线程占明显优势:序号大的,多线程占明显优势.单线程时间不稳定,多线程时间稳定. go语言测试代码如下: package mai ...

  10. 2020-05-21:es底层读写原理?倒排索引原理?

    福哥答案2020-05-21: es不熟悉,答案仅供参考:es写数据过程1.客户端选择一个node发送请求过去,这个node就是coordinating node(协调节点)2.coordinatin ...