Swagger 招摇过市:如何格式化示例json
我真的很难理解响应的Swagger 招摇过市:如何格式化示例json,swagger,swagger-ui,openapi,Swagger,Swagger Ui,Openapi,我真的很难理解响应的示例部分的格式。我为500内部服务器错误定义了以下响应 500InternalServerError: description: The server encountered an unexpected condition which prevented it from fulfilling the request schema: allOf: - $ref: '#/definitions/Failure' headers:
示例
部分的格式。我为500内部服务器错误定义了以下响应
500InternalServerError:
description: The server encountered an unexpected condition which prevented it from fulfilling the request
schema:
allOf:
- $ref: '#/definitions/Failure'
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
type: integer
examples:
application/json:
code: -1
message: The server encountered an unexpected condition which prevented it from fulfilling the request
当我在swagger ui中加载它时,它看起来如下所示:
如何将响应格式化为多行,并如下所示:
{
"code": "-1",
"message": "The server encountered an unexpected condition which prevented it from fulfilling the request"
}
在响应级别示例中缺少漂亮的打印似乎是Swagger UI 3.0.x中的一个缺陷或缺少功能。请随意提交一个问题 解决方法是使用架构级别的示例:
definitions:
Failure:
type: object
...
example:
code: "-1" # Quotes force the number to be treated as a string
message: The server encountered an unexpected condition which prevented it from fulfilling the request
顺便说一下,单独使用
$ref
时,您不需要allOf
(不与其他项目组合):
schema:
$ref: '#/definitions/Failure'