当前位置:网站首页>Swagger2 generates API documents
Swagger2 generates API documents
2022-04-23 06:33:00 【xingsfdz】
The precondition is that it has been used in the project swagger
One 、html Format :
1. Join the rely on swagger2markup
<!-- Document generation -->
<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<version>1.3.1</version>
</dependency>
2. generation 1 Use Test Class generation
import java.net.URL;
import java.nio.file.Paths;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@ContextConfiguration
public class ApiTest {
@Test
public void generateAsciiDocs() throws Exception {
// Output Ascii Format
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)// Multiple formats can be selected
// .withMarkupLanguage(MarkupLanguage.MARKDOWN)
.build();
Swagger2MarkupConverter.from(new URL("http://localhost:18080/v2/api-docs"))
.withConfig(config)
.build()
.toFolder(Paths.get("src/docs/asciidoc/generated"));
}
}
among http://localhost:18080/v2/api-docs For your project swagger json file , start-up swagger You can see
Generate corresponding after execution 4 A document :
The catalogue is :
src\docs\asciidoc\generated
3. Generate html
You need to add a plug-in to pom.xml
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<configuration>
<sourceDirectory>src/docs/asciidoc/generated</sourceDirectory>
<outputDirectory>src/docs/asciidoc/html</outputDirectory>
<backend>html</backend>
<sourceHighlighter>coderay</sourceHighlighter>
<attributes>
<toc>left</toc>
</attributes>
</configuration>
</plugin>
And then execute maven Use command :
Generate after execution html file : Inside is Api details . As long as you swagger It's quite standard , It's very standard here .
Okay This is a html The way .
Two 、 Another tool is recommended , Use showdoc
Official website :https://www.showdoc.com.cn/
Of course, this tool can also download code and deploy it to its own server , You can also use his online .
Register login -- New projects
Select import file :
Here, let's visit swagger Of :http://localhost:18080/xxx/v2/api-docs also ctrl+s Save as json Format The file of
google Tourist device
Then import to showdoc The above operation can generate api file , Very convenient .
版权声明
本文为[xingsfdz]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210614267647.html
边栏推荐
猜你喜欢
随机推荐
Integers have friends interval GCD + double pointer
Techniques et principes de détection
Basemap库绘制地图
根据SQL语句查询出的结果集,将其封装为json
[leetcode217] there are duplicate elements
爬西瓜视频url
程序设计训练
POI and easyexcel exercises
Plane semi intersecting plate
Rust 中的 Rc智能指针
scikit-learn sklearn 0.18 官方文档中文版
检测技术与原理
Event listener
Motor and drive (Qi Jinqing Edition)
队列解决约瑟夫问题
Addition, deletion, query and modification of data
安全授信
Explanation of login page
爬取彩票数据
爬取蝉妈妈数据平台商品数据