OpenAPI发布包含内容错误的响应201



我想使用OpenAPI v2设计一个API,并返回一个ID以响应POST请求。这就是我尝试的:

responses:
201:
description: item created
content:
application/json:
schema:
type: integer
example: 234
400:
description: invalid input, object invalid
409:
description: an existing item already exists

我正在使用Swagger HUB,它为响应201引发了以下错误:

should NOT have additional properties additionalProperty: content

出现此错误是因为您使用的语法(特别是content关键字(是OpenAPI 3.0,而不是2.0。

对应的OpenAPI 2.0语法为:

get:
produces:
- application/json
...
responses:
201:
description: item created
schema:
type: integer
example: 234

JSON有效载荷通常作为对象或数组而不是基元发送。我建议您将响应设置为JSON对象,例如{"id": 234}。在这种情况下,响应模式看起来像:

responses:
201:
description: item created
schema:
type: object
properties:
id:
type: integer
example: 234

最新更新