Swagger exports offline PDF API documents

Based on Swagger2MAKEUP plug-in and Asciidoctor to generate offline PDF Restful API documents.

The cause of

Swagger2 is used to generate development API documents in the project, but when cross-team or project delivery is involved, offline API documents need to be provided. When I tried to export offline documents with Swagger, I found that many articles of Baidu are basically similar with minor differences.

And many of them have to generate the corresponding offline asciidOC in the project, in the development of a separate Test case to carry out, while introducing other dependencies into the project, feel intrusive code, its own business does not need these dependencies, found combined with their own project a lot of things to modify. Swagger2makeup can be found in the client through the command line to achieve, is also very simple and do not invade the code, deliberately recorded to share.

Offline document generation

Asciidoc file named “swagger-doc.adoc” is generated in the current directory according to swagger2markup. This article uses a Docker image to create adoc files. You can also refer to the official website to generate adoC files from jars.

The Swagger2Markup JAR generates documentation

Swagger2markup cli address

docker run --rm -v $(pwd):/opt swagger2markup/swagger2markup convert -i "http://192.168.101.6:8016/v2/api-docs" -f /opt/swagger-doc
Copy the code

If it is a generated local JSON file, you can replace the URL link with a JSON file, for example, local/TMP /swagger.json

docker run --rm -v $(pwd):/opt swagger2markup/swagger2markup convert -i /tmp/swagger.json -f /opt/swagger-doc
Copy the code

Based on the generated adoc file, a file named swagger-doc. PDF is generated in the current directory.

docker run -it -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf swagger-doc.adoc
Copy the code

http://192.168.101.6:8016/v2/api-docs address content only part are shown here

{

swagger: "2.0",

info:- {

description: "Api Documentation",

version: "1.0",

title: "Api Documentation",

termsOfService: "urn:tos",

contact:{},

license:- {

name: "Apache 2.0",

url: "< http://www.apache.org/licenses/LICENSE-2.0 >"

}

},

host: "192.168.101.6:8016",

basePath: "/", tags:+ [... ] .Copy the code

View the result

qujianfei@troyMac  ~/docker/swagger_dir  ls qujianfei@troyMac disk ~/docker/swagger_dir dir dir run --rm -v $(pwd):/opt swagger2markup/swagger2markup convert -i "http://192.168.101.6:8016/v2/api-docs"- f/opt/swagger - doc 06:09:13, 641 [main] INFO IO. Swagger. Parser. The from Swagger20Parser - reading http://192.168.101.6:8016/v2/api-docs 06:09:15. 965. [the main] the DEBUG I.G.S.I.D ocument. PathsDocument - Generate examples is Disabled. 06:09:15. [the main] 965 DEBUG I.G.S.I.D ocument. PathsDocument - Create separated operation files is disabled. 06:09:15. 971. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Create separated definition files is disabled. 06:09:16. 836. [the main] INFO I.G.S.M.B.I.A sciidoc. AsciiDocBuilder - Markup document written to: / opt/swagger - doc. Adoc 06:09:17, 237 [main] the DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'linksUsingGET' (normalized id = 'linksUsingGET') 06:09:17. [the main] 288 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'handleUsingGET_2' (normalized id = 'handleUsingGET_2') 06:09:17. [the main] 333 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'handleUsingGET_1' (normalized id = 'handleUsingGET_1') 06:09:17. [the main] 455 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'handleUsingGET' (normalized id = 'handleUsingGET') 06:09:17. [the main] 554 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'handleUsingGET_3' (normalized id = 'handleUsingGET_3') 06:09:17. [the main] 680 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'addMonitorPluginUsingPUT_1' (normalized id = 'addMonitorPluginUsingPUT_1') 06:09:17. [the main] 738 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'tokenValidateUsingPOST_1' (normalized id = 'tokenValidateUsingPOST_1') 06:09:17. [the main] 774 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingPOST' (normalized id = 'errorHtmlUsingPOST') 06:09:17. [the main] 807 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingGET' (normalized id = 'errorHtmlUsingGET') 06:09:17. [the main] 841 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingPUT' (normalized id = 'errorHtmlUsingPUT') 06:09:17. [the main] 884 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingDELETE' (normalized id = 'errorHtmlUsingDELETE') 06:09:17. [the main] 907 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingPATCH' (normalized id = 'errorHtmlUsingPATCH') 06:09:17. [the main] 931 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingHEAD' (normalized id = 'errorHtmlUsingHEAD') 06:09:17. [the main] 963 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'errorHtmlUsingOPTIONS' (normalized id = 'errorHtmlUsingOPTIONS') 06:09:18. [the main] 068 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getAgentUsingGET' (normalized id = 'getAgentUsingGET') 06:09:18. [the main] 121 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'uploadAgentUsingPOST' (normalized id = 'uploadAgentUsingPOST') 06:09:18. [the main] 157 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'uploadProxyUsingPOST' (normalized id = 'uploadProxyUsingPOST') 06:09:18. [the main] 200 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getProxyUsingGET' (normalized id = 'getProxyUsingGET') 06:09:18. [the main] 243 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'updateAgentStatusUsingPOST' (normalized id = 'updateAgentStatusUsingPOST') 06:09:18. [the main] 291 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'createAgentsUsingPUT' (normalized id = 'createAgentsUsingPUT') 06:09:18. [the main] 343 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAgentsUsingGET_2' (normalized id = 'listAgentsUsingGET_2') 06:09:18. [the main] 374 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'createAgentUsingPUT' (normalized id = 'createAgentUsingPUT') 06:09:18. [the main] 414 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'addMonitorPluginUsingPUT' (normalized id = 'addMonitorPluginUsingPUT') 06:09:18. [the main] 443 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getPluginListUsingGET' (normalized id = 'getPluginListUsingGET') 06:09:18. [the main] 498 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'tokenValidateUsingPOST' (normalized id = 'tokenValidateUsingPOST') 06:09:18. [the main] 535 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'heartBeatUsingPOST' (normalized id = 'heartBeatUsingPOST') 06:09:18. [the main] 590 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getInstallerUsingGET' (normalized id = 'getInstallerUsingGET') 06:09:18. [the main] 624 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAgentsUsingGET' (normalized id = 'listAgentsUsingGET') 06:09:18. [the main] 649 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAllPluginInstallerUsingGET' (normalized id = 'listAllPluginInstallerUsingGET') 06:09:18. [the main] 671 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'updatePluginsUsingPATCH' (normalized id = 'updatePluginsUsingPATCH') 06:09:18. [the main] 733 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getAgentDetailByResIdUsingGET' (normalized id = 'getAgentDetailByResIdUsingGET') 06:09:18. [the main] 780 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'deleteAgentByResourceIdsUsingDELETE' (normalized id = 'deleteAgentByResourceIdsUsingDELETE') 06:09:18. [the main] 796 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAgentStatesUsingGET' (normalized id = 'listAgentStatesUsingGET') 06:09:18. [the main] 845 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getTopUpTimeUsingGET' (normalized id = 'getTopUpTimeUsingGET') 06:09:18. [the main] 863 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'agentDetailUsingGET' (normalized id = 'agentDetailUsingGET') 06:09:18. [the main] 900 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'deleteAgentUsingDELETE' (normalized id = 'deleteAgentUsingDELETE') 06:09:18. [the main] 927 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAgentsUsingGET_1' (normalized id = 'listAgentsUsingGET_1') 06:09:18. [the main] 958 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'cancelUsingGET' (normalized id = 'cancelUsingGET') 06:09:19. [the main] 027 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'runUsingPOST' (normalized id = 'runUsingPOST') 06:09:19. [the main] 088 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'countUsingGET' (normalized id = 'countUsingGET') 06:09:19. [the main] 105 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'countsUsingGET' (normalized id = 'countsUsingGET') 06:09:19. [the main] 127 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listUsingGET' (normalized id = 'listUsingGET') 06:09:19. [the main] 145 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'detailUsingGET' (normalized id = 'detailUsingGET') 06:09:19. [the main] 174 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'deleteUsingDELETE' (normalized id = 'deleteUsingDELETE') 06:09:19. [the main] 197 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'cancelUsingPOST' (normalized id = 'cancelUsingPOST') 06:09:19. [the main] 234 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'createUsingPUT' (normalized id = 'createUsingPUT') 06:09:19. [the main] 282 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'countUsingGET_1' (normalized id = 'countUsingGET_1') 06:09:19. [the main] 319 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'detailUsingGET_1' (normalized id = 'detailUsingGET_1') 06:09:19. [the main] 351 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'deleteUsingDELETE_1' (normalized id = 'deleteUsingDELETE_1') 06:09:19. [the main] 406 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'updateUsingPATCH' (normalized id = 'updateUsingPATCH') 06:09:19. [the main] 468 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'cancelUsingPOST_1' (normalized id = 'cancelUsingPOST_1') 06:09:19. [the main] 529 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'runUsingPOST_1' (normalized id = 'runUsingPOST_1') 06:09:19. [the main] 572 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listUsingGET_1' (normalized id = 'listUsingGET_1') 06:09:19. [the main] 633 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'getExecutionLogUsingGET' (normalized id = 'getExecutionLogUsingGET') 06:09:19. [the main] 743 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'createUsingPUT_1' (normalized id = 'createUsingPUT_1') 06:09:19. [the main] 800 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'changeFileToStringUsingGET' (normalized id = 'changeFileToStringUsingGET') 06:09:19. [the main] 841 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'checkedListUsingGET' (normalized id = 'checkedListUsingGET') 06:09:19. [the main] 956 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'runScriptUsingPOST' (normalized id = 'runScriptUsingPOST') 06:09:20. [the main] 011 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'detailUsingGET_2' (normalized id = 'detailUsingGET_2') 06:09:20. [the main] 074 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'deleteUsingDELETE_2' (normalized id = 'deleteUsingDELETE_2') 06:09:20. [the main] 111 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'updateUsingPATCH_1' (normalized id = 'updateUsingPATCH_1') 06:09:20. [the main] 126 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'contentUsingGET' (normalized id = 'contentUsingGET') 06:09:20. [the main] 152 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'checkUsingPOST' (normalized id = 'checkUsingPOST') 06:09:20. [the main] 163 DEBUG I.G.S.I.D ocument. PathsDocument - Operation processed:'listAllScriptsUsingGET' (normalized id = 'listAllScriptsUsingGET') 06:09:20. [the main] 218 INFO I.G.S.M.B.I.A sciidoc. AsciiDocBuilder - Markup document written to: / opt/swagger - doc. Adoc 06:09:20, 235 [main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Agent'06:09:20. 255. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'AgentParam'06:09:20. 257. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'AgentPlugin'06:09:20. 266. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'AgentPluginBinding'06:09:20. 271. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ExecDetailView'06:09:20. 279. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ExecutionConditionCounts'06:09:20. 280. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ExecutionItem'06:09:20. 291. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ExecutionListView'06:09:20. 302. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'HeartBeat'06:09:20. 304. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'JobDetailView'06:09:20. 308. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'JobItem'06:09:20. 314. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'JobListView'06:09:20. 317. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'JobNode'06:09:20. 320. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'JobRequest'06:09:20. 335. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Link'06:09:20. 336. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'LogEntry'06:09:20. 339. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'LogView'06:09:20. 341. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'the Map « string, Link »'06:09:20. 343. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'the Map « string, long »'06:09:20. 345. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'the Map « string, the string »'06:09:20. 350. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ModelAndView'06:09:20. 354. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Node'06:09:20. 361. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'NodeStepState'06:09:20. 368. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Option'06:09:20. 373. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue PagedResultBean SmartAgent'06:09:20. 375. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'PluginParam'06:09:20. 378. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean'06:09:20. 388. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean AgentPluginBinding'06:09:20. 392. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean AgentPlugin'06:09:20. 393. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean Agent'06:09:20. 394. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ExecDetailView'06:09:20. 399. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ExecutionItem'06:09:20. 407. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ExecutionListView'06:09:20. 410. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean JobDetailView'06:09:20. 411. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean JobListView'06:09:20. 413. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « List « AgentPlugin » »'06:09:20. 415. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « List « ExecutionConditionCounts » »'06:09:20. 420. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « « List Map « string, long » » »'06:09:20. 424. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « « List are Script » »'06:09:20. 428. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « List « SmartAgent » »'06:09:20. 433. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « « List string » »'06:09:20. 436. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean LogView06:09:20. 440. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ResultBean « Map « string, the string » »'06:09:20. 444. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ScriptContent'06:09:20. 446. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ScriptDetailView'06:09:20. 450. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean ScriptListView'06:09:20. 452. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean SmartAgent'06:09:20. 454. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean int'06:09:20. 455. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean long'06:09:20. 458. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'issue ResultBean string'06:09:20. 459. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'RunCmdParam'06:09:20. 463. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'RunScriptParam'06:09:20. 475. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Script'06:09:20. 484. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ScriptContent'06:09:20. 487. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ScriptDetailView'06:09:20. 492. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ScriptItem'06:09:20. 501. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'ScriptListView'06:09:20. 510. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'SmartAgent'06:09:20. 516. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'TokenValidateParam'06:09:20. 522. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'View'06:09:20. 529. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'Workflow'06:09:20. 531. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'WorkflowStep'06:09:20. 537. [the main] the DEBUG I.G.S.I.D ocument. DefinitionsDocument - Definition processed:'WorkflowWorkflowStep'06:09:20. 562. [the main] INFO I.G.S.M.B.I.A sciidoc. AsciiDocBuilder - Markup document written to: / opt/swagger - doc. Adoc 06:09:20. [the main] 573 INFO I.G.S.M.B.I.A sciidoc. AsciiDocBuilder - Markup document written to: Adoc qujianfei@troyMac  ~/docker/swagger_dir  ls swagger-doc.adoc qujianfei@troyMac port ~/docker/swagger_dir  docker run it -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf swagger-doc.adoc qujianfei@troyMac  ~/docker/swagger_dir  Adoc swagger-doc. PDF qujianfei@troyMac  ~/docker/swagger_dir Copy the code

Viewing PDF files

Swagger configuration

build.gradle

    implementation 'the IO. Springfox: springfox - swagger2:2.9.2'
    compile group: 'com.github.xiaoymin'. name: 'swagger-bootstrap-ui'. version: '1.9.6'
Copy the code

The spring configuration class

package com.troy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api(a) {
        return newDocket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build();  }protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/"); }}Copy the code

Swagger configuration here only pastes part of the code in the project. In actual use, there is no need to keep the same with swagger. As long as swagger2 is introduced, swagger JSON file can be generated.

At the end

The overall use of swagger2Makeup plug-in and Asciidoctor offline document generation method is simple to operate and less invasive code, and almost no learning cost, can be plug-and-play, can fully meet the general requirements. However, there are some remaining problems in this example, that is, the font configuration of PDF, which will not be explored too much this time. If you have time to continue to explore the font Settings later, you are welcome to discuss with anyone if they have a plan.