在inlinux环境中,Swagger可以自动以多种方式更新API文档。 Some common methods are: Using swagger codegen on Linux systems, you can use the following commands:
16🔥wgethttps://repo1.maven.org/maven2/io/swagger/swagger-codegen-codegen-code-cli/2.4.21/swagger-codegen-cl-4.21.jar -o -o Openapi-Generator.jar
22🔥writingApi规范文件:
h]
26
wwswageapi api api api api api apifification fieffification openape fieffification(oas)。
swagger.json
format。
32Penapi:35🔥3.33.037Info:
477🔥Version:47🔥 /用户:get:Summary:61🔥list6365🔥usersRES:'200 ':Description:737476🔥777778users🔥 80🔥
Content:
Type:89
ITEMS:
🔥8 5🔥Schema:
Type:89
ITEMS:
Schema:
Type:89🔥Array
Items:
Schema:🔥86 schema: ref: 95🔥 '#/components/schemas/user'components: schemas: type: 105106🔥properties:
ID:
Type:113🔥Integr114🔥
Name:
Type: 123🔥String
126🔥
130🔥集合到构建过程:
🔥133-swagger将Codgen集成到Maven或Gradle的构建过程中,以便与每个构建自动生成代码和文档。
136🔥mavenexample:
140<Build149<150🔥plugin151149149149149🔥 <groupID🔥155>Openapitools157🔥</groupid160🔥
Penapitools</groupID160🔥<groupId155156🔥Openapitools157🔥 <ARTIFACTID>openapi-generator-maven-plugin</🔥1666ArtifactId168🔥 <171🔥>5.2.2.1</version175🔥><185🔥< 86🔥<Execution283<189🔥<Goal>192🔥Generate193</Goal🔥19519597🔥</Goals199🔥>
<Configuration2203🔥>
<Inputspec207🔥>$ {project.basedir}/src/main/Resources/swagger.yaml</Inputspec> <GeneratorName>JAVA217🔥</</🔥generatorname220🔥 <generatorName>JAVA217🔥</</220🔥<🔥222222222222222222222222222222222222222222224🔥$ {project.build.directory}/生成的sources</output228🔥</🔥230config-configuration </Execution236🔥238🔥Executions239
242plugin2444🔥 🔥 245🔥</Plugins>
</Build251🔥>
254🔥
与弹簧框架集成的开源项目,用于根据Swagger规范自动生成API文档。
-
264🔥ddspringfox依赖项:🔥2666
添加Spring Fox依赖项POM.xml
271273🔥<275<279280🔥io.springfox🔥28 1285🔥<ARTIFACTID>Springfox-swagger2290🔥ArtifactIf291🔥293< </依赖性><依赖性3088“ <Dependency308🔥
<Dependency308🔥
<Dependency308🔥
<Dependency308🔥
<ArifactId>Springfox-swagger-ui</🔥32222<version🔥3273273.328🔥2.9.9.9.9.9.29292929292929292929🔥版本331🔥></dependencies335🔥>
338🔥
340🔥
控制:
348@configuration@enableswagger2public354🔥3555555🔥class
@beanPublicdocket363365🔥()🔥3666🔥{🔥367.select(histect) privateapiInfoapiinfotle(“我的API”) .DESCRIPTION(“我的API描述”
397AccessSwaggerui:
8080/Swagger-ui.htmlView。 API文档。
420421🔥4221
424🔥
425426426
🔥
flask436🔥flaskFROM438🔥FLASK_RESTPLUSIMPORTAPI,资源 app = flask(__名称__) API(API,API(APP,title ='bookManagementapi'442🔥,描述='asimple库管理系统API'144441)操作{'Id'452🔥:fields.integer(description ='bookid'154🔥), fields.string(description ='bookTitle'),
(描述='author'1462🔥) @ns.Route('/'/'467[ Books'1478🔥) @ns.marshal_list_with(Book_model)def487🔥Get(Self) 'Beginnerpython'1502'author':'zhangsan'''I506🔥}]
'/'5112Class51515book(Uresource) @ns.doc(ns.doc(🔥5520521🔥 (Book_model)ID536🔥):”“”“获得基于ID的书籍信息”,“获得基于ID”的书籍信息,“
#x27;,'author':'zhangsan'1552🔥} 554🔥🔥5551🔥5551🔥5551
558🔥 Run Application560🔥
运行访问您的应用程序和根路径(默认为http:// localhost:5000/
),您可以看到美丽的Swagger UI接口。
上述方法允许在Linux环境中自动更新Swagger API文档,从而提高了文档管理的开发效率和便利性。
570🔥
上述内容来自Internet,并不代表此站点的所有视图! 关注我们:zhujipindao .com
评论前必须登录!
注册