Skip to content

Enum as a response generates incorrect factory function #48

Description

@martyan

When an enum is referenced directly as the response schema, react-query-swagger generates a factory function that incorrectly references a non-existent initializer.

swagger.json

{
    "openapi": "3.0.1",
    "info": {
        "title": "API 1.0",
        "description": "REST API",
        "version": "1.0"
    },
    "paths": {
        "/api/product/{id}/availability": {
            "get": {
                "operationId": "getProductAvailability",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "format": "int64"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Fetching the product availability was successful.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ProductAvailabilityType"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "ProductAvailabilityType": {
                "type": "string",
                "enum": [
                    "NotSet",
                    "Unavailable",
                    "Available"
                ],
                "description": "Differentiates types of availability."
            }
        }
    }
}

Run this script to generate API:
npx react-query-swagger /tanstack /input:swagger.json /output:client.ts /template:Axios /use-recommended-configuration /minimal

Output:

...
export function initPersister() {
  // initProductAvailabilityType does not exist
  addResultTypeFactory('Client___getProductAvailability', (data: any) => Types.initProductAvailabilityType(data));
}
...

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