Swagger 招摇过市:在响应对象中使用特定值
我正在用swagger创建API文档,但我找不到在响应中表示特定值的方法 例如,当API中存在404错误时,响应如下:Swagger 招摇过市:在响应对象中使用特定值,swagger,Swagger,我正在用swagger创建API文档,但我找不到在响应中表示特定值的方法 例如,当API中存在404错误时,响应如下: { "code": 404, "result": "payment.notfound" } /paths: /foo: /get: parameters: [] responses: 200: description: it worked 404: de
{
"code": 404,
"result": "payment.notfound"
}
/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
该值将始终为404,这如何可以用招摇来表示
谢谢 您可以这样:
{
"code": 404,
"result": "payment.notfound"
}
/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"
这意味着,“它是一个字符串,但永远只能是这个值”