react-query-swagger
react-query-swagger copied to clipboard
Enum as a response generates incorrect factory function
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));
}
...