Rom*_*'ai 1 swagger swagger-2.0
我有几个API,所有这些API都返回一个名为的布尔字段的JSON success.
API 1
{"success": true, "data": "some data"}
API 2
{"success": false, "error": "error message"}
我可以用模板之类的东西编写swagger 2.0文档,所以我不需要像这样在每个API中复制和粘贴成功字段部分吗?
responses:
200:
schema:
properties:
success:
type: boolean
description: true if the request is successful.
data:
...
和
responses:
200:
schema:
properties:
success:
type: boolean
description: true if the request is successful.
error:
...
谢谢!
是的,allOf用于常见字段:
responses:
200:
schema:
allOf:
- $ref: '#/definitions/common'
- properties:
data:
# your details here
definitions:
Common:
type: object
properties:
success:
type: boolean
description: true if the request is successful.
Run Code Online (Sandbox Code Playgroud)
也:
schema:
allOf:
- $ref: '#/definitions/Common'
- properties:
data:
$ref: '#/definitions/Another'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1398 次 |
| 最近记录: |