Reputation: 5070
I want to design an API using OpenAPI v2 having returning an ID in response of a POST request. This is what I tried:
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
I am using Swagger HUB and it raises the following error for response 201:
should NOT have additional properties additionalProperty: content
Upvotes: 1
Views: 4286
Reputation: 98011
The error occurs because the syntax you're using (specifically, the content
keyword) is OpenAPI 3.0, not 2.0.
The corresponding OpenAPI 2.0 syntax is:
get:
produces:
- application/json
...
responses:
201:
description: item created
schema:
type: integer
example: 234
JSON payloads are usually sent as objects or arrays rather than primitives. I recommend that you make your response a JSON object, e.g. {"id": 234}
. In this case, the response schema would look like:
responses:
201:
description: item created
schema:
type: object
properties:
id:
type: integer
example: 234
Upvotes: 1