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 array_search() 函数

    实例 在数组中搜索键值 "red",并返回它的键名: <?php$a=array("a"=>"red","b" ...

  2. Vue Router详细教程

    1.什么是路由 1.1路由简介 说起路由你想起了什么?路由是一个网络工程里面的术语. 路由(routing)就是通过互联的网络把信息从源地址传输到目的地址的活动. --- 维基百科 额,啥玩意? 没听 ...

  3. 关于c/c++指针,指针的指针

    伪军迷祝:建军节快乐! 当调用一个函数时,实际上入参使用的都是副本(除非是引用),指针也不例外.举个例子如: void func(int a, int * p); 当调用func时无论是a还是p其实传 ...

  4. Kaggle-pandas(1)

    Creating-reading-and-writing 戳我进原网站 教程 1.创建与导入 DataFrame import pandas as pd pd.DataFrame({'Yes': [5 ...

  5. 打开IDEA后tomcat不能用,Cannot load project of unknown project type,无法加载类或者项目

    这一问题在网络中有比较统一的解决方法,我这个也是按这个方法解决的. 问题出现的前提和原因: 一个运行正常项目,我关闭后第二天打开发现tomcat不能用了. 解决方法: 我查了一下,这是一个IDEA软件 ...

  6. Phthon环境搭建

    一,官网去下载 https://www.python.org/downloads/ 二,安装 三,验证python 四.IPython IPython 是一个 python 的交互式 shell,比默 ...

  7. Java—时间的原点 计算时间所使用的 Date类/DateFormat类/Calendar类

    Date类 类 Date 表示特定的瞬间,精确到毫秒. 毫秒概念:1000毫秒=1秒 毫秒的0点: System.currentTimeMillis()  返回值long类型参数 用于获取当前日期的毫 ...

  8. cocos-2d解决rapidjson的string参数转换

    解决方法 AddMember的传入的参数不是string, 所以会报错 本质就是把string类型转换成 参数的类型 username = "string"; rapidjson: ...

  9. Manacher(马拉车)算法(jekyll迁移)

    layout: post title: Manacher(马拉车)算法 date: 2019-09-07 author: xiepl1997 cover: 'assets/img/manacher.p ...

  10. PHP 开发工程师基础篇 - PHP 字符串

    字符串 (String) 字符串是一系列字符的集合.如 “abc”. 在 PHP 中,一个字符代表一个字节,一个字节 (Byte) 有 8 比特 (bit). PHP 仅支持 256 字符集,因此 P ...