Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OpenAPI Post response 201 with content error

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading