Skip to content

Response 204 throws exception instead of success #49

Description

@martyan

If path returns both 200 and 204 responses, the generated code throws error on 204 if schema is expected on 200.

Repro steps

swagger.json:

{
    "openapi": "3.0.1",
    "info": {
        "title": "API 1.0",
        "description": "REST API",
        "version": "1.0"
    },
    "paths": {
        "/product": {
            "post": {
                "summary": "Create product",
                "operationId": "productPost",
                "responses": {
                    "200": {
                        "description": "Success",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ProductResponse"
                                }
                            }
                        }
                    },
                    "204": {
                        "description": "No Content"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "ProductResponse": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    }
                },
                "additionalProperties": false
            }
        }
    }
}

Run this script to generate API:

npx react-query-swagger /tanstack /input:swagger.json /output:client.ts /template:Axios /use-recommended-configuration /minimal

Output:

image

Proposed behaviour

Response 204 should not throw exception.

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions