我正在使用swagger创建API文档,但我找不到在响应中表示特定值的方法。
例如,当API中出现404错误时,响应如下:
{
"code": 404,
"result": "payment.notfound"
}
该值将始终为404,如何以夸张的方式表达。
谢谢!
答案 0 :(得分:4)
你可以这样:
/paths:
/foo:
/get:
parameters: []
responses:
200:
description: it worked
404:
description: "it didn't work"
schema:
type: object
properties:
code:
type: integer
format: int32
result:
type: string
如果确实想要说result
只能是字符串payment.notfound
,那么您只需设置一个枚举:
result:
type: string
enum:
- "payment.notfound"
这意味着,“它只是一个字符串,但只能是这个值。”