0

We have problem with our generated API consumers.

Tried typescript-fetch and Java-SpringBoot generators.

If the endpoint has no documents for given id, the endpoint responses with a 204 code and an empty body.

But the generated controller code tries to parse the empty body as if it were a 200 code and leads into a parsing error.

swagger spec:

/api/v1/{id}/documents:
get:
  tags:
  - documents
  summary: Gets the list of documents for id.
  operationId: getDocs
  parameters:
  - name: id
    in: path
    required: true
    schema:
      type: string
  responses:
    "200":
      description: Returns the document-list
      content:
        application/json:
          schema:
            type: array
            items:
              $ref: '#/components/schemas/AbstractCoEntry'
    "204":
      description: no documents in list
    "401":
      description: User is not authorized to read the documents
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorToken'

How do I need to specify the swagger endpoint to avoid the JSON parsing on consume?
Or how to handle this setup correctly for empty responses?

Gregor Sklorz
  • 170
  • 1
  • 3
  • 13
  • This is slightly offtopic, but the best practice for returning empty collections and sub-collections is to use [status 200 with an empty list](https://stackoverflow.com/q/13564031/113116), not 204. – Helen Jul 04 '23 at 12:17

0 Answers0