astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
717 stars 80 forks source link

No support for 204 responses #274

Open kornysietsma opened 5 months ago

kornysietsma commented 5 months ago

204 response types are not exposed in the generated API, even if they are in the OpenAPI schema. This is surprising as 4xx errors are clearly exposed - at minimum it'd be good for the generated client to give some indication to users that they should handle 204 as a possible response type.

Also a 204 without content is handled a bit ungracefully - we get an AxiosError: maxContentLength size of -1 exceeded error - (actually this might be an Axios bug - https://github.com/axios/axios/issues/5286 )

UPDATE: half way through writing this I found https://github.com/ecyrbe/zodios/issues/307 marked as 'wontfix' :(

This might be a showstopper for us - we have quite a few existing services that return 204 responses, rightly or wrongly!

So possibly the only fix might be to add this to the README to save people time who have this need. (and we will try typed-openapi and an alternative fetcher )

Minimal reproduction

openapi: 3.0.1
info:
  title: sample
  version: '1.0'
paths:
  /api/FooBar:
    get:
      parameters:
        - name: thingy
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  fooId:
                    type: string
                additionalProperties: false
        '204':
          description: No Content

Expected behavior A client which might return 204 would return an .optional() schema so it was clear to developers that they need to handle 204 responses (though we'd also need a way to identify that the response was not a 200) (also this might not work still due to https://github.com/axios/axios/issues/5286 )