当前位置:网站首页>使用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());边栏推荐
- Theoretical basis of machine learning
- Introduction to MapReduce
- Machine vision learning summary
- [deep learning] (III) image classification
- DNS domain name resolution service
- I'm interested in reading efficient reading - the most cost-effective self investment
- SSM整合
- Career planning route
- Learning pyramid context encoder network for high quality image painting paper notes
- generator生成器,只生成两个方法
猜你喜欢

Drools development decision table

SSH service

Scikit learn -- steps of machine learning application development

PSO and mfpso
![[database connection] - excerpt from training](/img/7d/334b4b7f0f6e1de228c4ecb1e600a3.png)
[database connection] - excerpt from training

PPPoE网关模拟环境搭建

JMeter FAQs

利用a*启发式搜索解决迷宫寻路问题

浅谈不可转让的声誉积分NFT SBTs面临的困境

The world's first large aerospace model came out. Wenxin's second supplement "Fuchun Mountain Residence map" is Baidu Pratt Whitney AI's perseverance
随机推荐
Codeforce:d2. remove the substring (hard version) [greedy string + subsequence]
Introduction to 51 single chip microcomputer (dedicated to the most understandable article for beginners)
PSO and mfpso
EMQX 简单使用
High performance architecture design of wechat circle of friends
Token of space renewable energy
Learning pyramid context encoder network for high quality image painting paper notes
IDEA:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“.
JDBC MySQL basic operations
Globally and locally consistent image completion paper notes
Hotel IPTV digital TV system solution
1. Pedestrian recognition based on incremental occlusion generation and confrontation suppression
The difference between run and start in thread class
Tips for using the built-in variable props of BeanShell
网NN计算能主机系统资e提供的NTCP
Problems encountered in configuring Yum source
Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem
1. There is a fractional sequence: 2/1, 3/2, 5/3, 8/5, 13/8,... Program to sum the first 20 items of this sequence.
Smart pointer, lvalue reference, lvalue reference, lambda expression
Kingbase v8r6 cluster installation and deployment case - script online one click capacity reduction