react-query-swagger icon indicating copy to clipboard operation
react-query-swagger copied to clipboard

Response 204 throws exception instead of success

Open martyan opened this issue 5 months ago • 0 comments

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

martyan avatar Sep 12 '24 15:09 martyan