当前位置:网站首页>使用swagger2markup生成API文档
使用swagger2markup生成API文档
2022-07-24 05:15:00 【kse_music】
一、引入依赖
1. 新版
<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<version>1.3.2</version>
</dependency>
2. 旧版
<dependency>
<groupId>io.github.robwin</groupId>
<artifactId>swagger2markup</artifactId>
<version>0.9.2</version>
</dependency>二、读取swagger.json生成ASCIIDOC或者MARKDOWN
1. 新版
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withPathsGroupedBy(GroupBy.TAGS)
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)
.withOutputLanguage(Language.ZH)
.build();
try {
Swagger2MarkupConverter.from(new URL("http://192.168.1.9:8888/api/swagger.json"))
.withConfig(config)
.build()
.toFolder(Paths.get("src/docs"));
} catch (MalformedURLException e) {
e.printStackTrace();
}2. 旧版
Swagger2MarkupConverter.from("json" + "/swagger.json")
.withPathsGroupedBy(GroupBy.TAGS)/
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)
.build()
.intoFolder("doc");三、利用maven插件asciidoctor-maven-plugin生成HTML5或PDF
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<configuration>
<sourceDirectory>${project.basedir}/src/docs</sourceDirectory>
<sourceDocumentName>index.adoc</sourceDocumentName>
<attributes>
<doctype>book</doctype>
<toc>left</toc>
<toclevels>3</toclevels>
<numbered></numbered>
<hardbreaks></hardbreaks>
<sectlinks></sectlinks>
<sectanchors></sectanchors>
<generated>${project.basedir}/src/docs</generated>
</attributes>
</configuration>
<executions>
<execution>
<id>output-html</id>
<phase>test</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html5</backend>
<outputDirectory>${project.basedir}/src/docs2</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>四、执行命令mvn clean package
五、第三步亦可以用maven插件替代、第四步中亦可以用java代码替代生成
1. 如下是替代第三步做法
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>false</springmvc>
<locations>com.hiekn.demo.rest</locations>
<schemes>http,https</schemes>
<host>192.168.1.119:8080</host>
<basePath>/api</basePath>
<info>
<title>PlantRobot CMS API</title>
<version>v1</version>
<description>
</description>
<termsOfService>
http://blog.csdn.net/dh798417147
</termsOfService>
<contact>
<email>[email protected]</email>
<name>dinghao</name>
<url>http://blog.csdn.net/dh798417147</url>
</contact>
<license>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<name>Apache 2.0</name>
</license>
</info>
<securityDefinitions>
</securityDefinitions>
<swaggerDirectory>${basedir}/json</swaggerDirectory>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-hibernate-validations</artifactId>
<version>1.5.6</version>
</dependency>
</dependencies>
</plugin>2. 如下是替代第四步做法
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>1.5.6</version>
</dependency>
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
Attributes attributes = new Attributes();
attributes.setCopyCss(true);
attributes.setLinkCss(false);
attributes.setSectNumLevels(3);
attributes.setAnchors(true);
attributes.setSectionNumbers(true);
attributes.setHardbreaks(true);
attributes.setTableOfContents(Placement.LEFT);
attributes.setAttribute("generated", "F:\\IDEAProject\\meta-boot\\src\\docs");
OptionsBuilder optionsBuilder = OptionsBuilder.options()
.backend("html5")
.docType("book")
.eruby("")
.inPlace(true)
.safe(SafeMode.UNSAFE)
.attributes(attributes);
String asciiInputFile = "src/docs/index.adoc";
asciidoctor.convertFile(
new File(asciiInputFile),
optionsBuilder.get());边栏推荐
- Infineon launched the world's first TPM security chip with post quantum encryption technology for firmware update
- [Huang ah code] Introduction to MySQL - 3. I use select *, and the boss directly rushed me home by train, but I still bought a station ticket
- The difference between statement and Preparedstatement and how to use placeholders
- [basic 7] - exceptions, capture and customize exceptions
- Smart pointer, lvalue reference, lvalue reference, lambda expression
- JDBC MySQL basic operations
- 网NN计算能主机系统资e提供的NTCP
- Emqx simple to use
- 酒店IPTV数字电视系统解决方案
- Career planning route
猜你喜欢

PXE efficient batch network installation

DHCP principle and configuration

Image to image translation with conditional advantageous networks paper notes

The difference between run and start in thread class

Chapter5 foundation of deep learning

How to set up an internal wiki for your enterprise?

Image painting for irregular holes using partial revolutions paper notes

Recursive cascade network: medical image registration based on unsupervised learning

Drools 开发决策表

Echo speaker pairing and operation method
随机推荐
Reading excerpts from Liu run's "bottom logic"
Data annotation learning summary
泛型和注解
Blue Bridge Cup 31 day sprint 21 day (C language)
13. Write a program, in which a user-defined function is used to judge whether an integer is a prime number. The main function inputs a number and outputs whether it is a prime number.
线程的介绍
Transpose of array sparse matrix
MapReduce concept
Image painting for irregular holes using partial revolutions paper notes
C primer plus learning notes - 6. Arrays and pointers
NumPy 统计相关函数示例教程
C primer plus learning notes - 5. Pointer
Kingbase v8r6 cluster installation and deployment case - script online one click expansion
How to avoid the most common mistakes when building a knowledge base?
Embedded system transplantation [2] - Construction of cross development environment
Knowledge record of College Physics C in advance in summer [update]
Numpy statistical correlation function example tutorial
The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands
C#表格数据去重
连接数%的准确率。现在拟需求。企业在数足以