当前位置:网站首页>[solved] how to generate a beautiful static document description page
[solved] how to generate a beautiful static document description page
2022-07-06 01:24:00 【A rookie is a great God】
Often asked recently ITMuch API How to make document pages , Considering the slightly complicated steps , Write a note to summarize .
TIPS
ITMuch API It's a personal video on Muke website 《 Microservices for the future :Spring Cloud Alibaba From entry to advanced 》 Supporting documents for practical projects .
effect

The overall steps
- Integrate Swagger, Generate Swagger Describe the endpoint
/v2/api-docs - Use
swagger2markup-maven-plugin, take/v2/api-docsGenerate ASCIIDOC file ; - Use
asciidoctor-maven-plugin, take ASCIIDOC File conversion to HTML; - Deploy
Integrate Swagger
TIPS
Swagger Is very simple to use , This article will not discuss , Please check the usage of Baidu by yourself .
Commonly used annotations :
- @Api
- @ApiOperation
- @ApiModel
- @ApiModelProperty
Plus dependence
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<!-- swagger --> <!-- The reason to exclude , It is because if it is not excluded, it will report NumberFormatException Warning of . --> <!-- Reference resources :https://github.com/springfox/springfox/issues/2265--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </exclusion> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.21</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.21</version> </dependency>To configure Swagger( Configure according to your own needs , The following configuration codes are for reference only )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/** * @author itmuch.com */ @Configuration @EnableSwagger2 public class SwaggerConfiguration { /** * swagger Information * * @return Page information */ private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("ITMuch API") .description("ITMuch API") .termsOfServiceUrl("") .version("1.0.0") .contact(new Contact("", "", "")).build(); } @Bean public Docket customImplementation() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.itmuch")) .paths(PathSelectors.any()) .build() .apiInfo(this.apiInfo()); //.globalOperationParameters(parameters); } }Interface for Swagger annotation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
@RestController @RequestMapping("/notices") @RequiredArgsConstructor(onConstructor = @__(@Autowired)) @Api(tags = " Announcement related interfaces ", description = " Announcement related interfaces ") public class NoticeController { /** * Check the latest announcement * * @return Announcement list */ @GetMapping("/newest") @ApiOperation(value = " Check the latest announcement ", notes = " be used for : Notice ") public Notice findNewest() { return new Notice(); } } @AllArgsConstructor @NoArgsConstructor @Builder @Data @ApiModel(" Notice ") public class Notice { /** * ID */ @ApiModelProperty("id") private Integer id; /** * Announcement content */ @ApiModelProperty(" Announcement content ") private String content; ... }
- such , After the application is started , There will be one
/v2/api-docsEndpoint , Describe your API Information about .
Generate ASCIIDOC
stay pom.xml To add the following :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <build>
<plugins>
<plugin>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<!-- api-docs visit url -->
<swaggerInput>http://localhost:8080/v2/api-docs</swaggerInput>
<!-- Generate as a single document , The output path -->
<outputFile>src/docs/asciidoc/generated/all</outputFile>
<config>
<!-- ascii Format document -->
<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
<swagger2markup.pathsGroupedBy>TAGS</swagger2markup.pathsGroupedBy>
</config>
</configuration>
</plugin>
...
|
swagger2markup-maven-plugin The function of the plug-in is to read http://localhost:8080/v2/api-docs Information about , Generate ASCIIDOC file . Of course, you can also generate other formats , such as Markdown wait .
This plug-in also has a lot of gestures , See GitHub - Swagger2Markup/swagger2markup-maven-plugin: A Swagger2Markup Maven Plugin
Generate HTML
below , Only need to ASCIIDOC convert to html Just OK 了 , stay pom.xml To add the following :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<configuration>
<!-- asciidoc Document input path -->
<sourceDirectory>src/docs/asciidoc/generated</sourceDirectory>
<!-- html Document output path -->
<outputDirectory>src/docs/asciidoc/html</outputDirectory>
<backend>html</backend>
<sourceHighlighter>coderay</sourceHighlighter>
<!-- html Document format parameters -->
<attributes>
<doctype>book</doctype>
<toc>left</toc>
<toclevels>3</toclevels>
<numbered></numbered>
<hardbreaks></hardbreaks>
<sectlinks></sectlinks>
<sectanchors></sectanchors>
</attributes>
</configuration>
</plugin>
|
asciidoctor-maven-plugin The plug-in also has many poses , See :GitHub - asciidoctor/asciidoctor-maven-plugin: A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
The generated file is in src/docs/asciidoc/html ( Look at the configuration of your plug-in ), Then you can get a NGINX Deployed .
Use
- Start the application
- perform
mvn swagger2markup:convertSwagger2markupGenerate ASCIIDOC - perform
mvn asciidoctor:process-asciidocGenerate html
边栏推荐
- Three methods of script about login and cookies
- Superfluid_ HQ hacked analysis
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- VMware Tools安装报错:无法自动安装VSock驱动程序
- Paging of a scratch (page turning processing)
- 程序员搞开源,读什么书最合适?
- How to see the K-line chart of gold price trend?
- 视频直播源码,实现本地存储搜索历史记录
- Convert binary search tree into cumulative tree (reverse middle order traversal)
猜你喜欢

Huawei Hrbrid interface and VLAN division based on IP

有谁知道 达梦数据库表的列的数据类型 精度怎么修改呀

关于softmax函数的见解

Who knows how to modify the data type accuracy of the columns in the database table of Damon

3D模型格式汇总

现货白银的一般操作方法

leetcode刷题_验证回文字符串 Ⅱ

Five challenges of ads-npu chip architecture design

282. Stone consolidation (interval DP)

1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once
随机推荐
视频直播源码,实现本地存储搜索历史记录
Spir - V premier aperçu
激动人心,2022开放原子全球开源峰会报名火热开启
黄金价格走势k线图如何看?
MUX VLAN configuration
Leetcode 208. Implement trie (prefix tree)
ORA-00030
yii中console方法调用,yii console定时任务
电气数据|IEEE118(含风能太阳能)
FFT learning notes (I think it is detailed)
在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
SCM Chinese data distribution
Leetcode1961. Check whether the string is an array prefix
SPIR-V初窥
leetcode刷题_反转字符串中的元音字母
Docker compose configures MySQL and realizes remote connection
Redis' cache penetration, cache breakdown, cache avalanche
Unity VR resource flash surface in scene
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
PHP error what is an error?