参考博客: python 如何使用swagger
Swagger Editor案例:Swagger Editor
Swagger官网
1. 编写yml
获取数据列表
This is the language awesomeness API
Call this api passing a language name and get back its features
---
tags:
- xxx API
description: ""
parameters:
- name: page_size
in: query
type: integer
description: size of each data page
required: false
- name: page_num
in: query
type: integer
description: page of data list
required: false
- name: status_s
in: query
type: string
description: data status
required: false
responses:
500:
description: Error get data list failed!
200:
description: The data list
content:
application/json:
examples:
200:
value: {
"code": 200,
"total": 2,
"page_num": 1,
"page_size": 20,
"data": [{xxx
},{
xxx
}]
}
summary: "相应Collection定义的JSON格式数据记录"
2. 使用@swag_from 装饰器
from flasgger import Swagger, swag_from
3. 运行main.py测试接口
4. post方法 测试
保存数据
This is the language awesomeness API
Call this api passing a language name and get back its features
---
tags:
- xxx API
description: 保存数据
parameters:
- name: body
in: body
description: save obj and its obj list
required: true
schema:
$ref: "#/definitions/Project"
responses:
400:
description: Invalid param value!
20000:
description: save success
content:
application/json:
examples:
20000:
value: {
"code": 200,
"data": "",
"error_msg": "保存成功"
}
- 方法引入@swag_from
- post方法接口测试
|