7nohe / openapi-react-query-codegen

OpenAPI React Query Codegen is a code generator for creating React Query (also known as TanStack Query) hooks based on your OpenAPI schema.
https://openapi-react-query-codegen.vercel.app
MIT License
298 stars 30 forks source link

Generating code and running TSC errors with TS2742 #118

Open sourceful-mia opened 6 months ago

sourceful-mia commented 6 months ago

Describe the bug When I run TSC after running codegen on a simple open api spec, I get error TS2742. It seems that this lib is missing some typings in the generated code.

To Reproduce Steps to reproduce the behavior:

Generated code with the attached swagger file, and run TSC on it.

OpenAPI spec file If possible, please upload the OpenAPI spec file.

{
    "openapi": "3.0.0",
    "components": {
        "examples": {},
        "headers": {},
        "parameters": {},
        "requestBodies": {},
        "responses": {},
        "schemas": {
            "UUID": {
                "type": "string",
                "description": "Stringified UUIDv4.\nSee [RFC 4112](https://tools.ietf.org/html/rfc4122)"
            },
            "Project": {
                "properties": {
                    "shared_with_client": {
                        "type": "boolean"
                    },
                    "updated_by": {
                        "$ref": "#/components/schemas/UUID"
                    },
                    "last_updated": {
                        "type": "string"
                    },
                    "date_created": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "id": {
                        "$ref": "#/components/schemas/UUID"
                    }
                },
                "required": [
                    "shared_with_client",
                    "updated_by",
                    "last_updated",
                    "date_created",
                    "name",
                    "id"
                ],
                "type": "object"
            },
            "ApiInternalError": {
                "properties": {
                    "message": {
                        "type": "string"
                    }
                },
                "required": [
                    "message"
                ],
                "type": "object"
            },
            "ApiResponseListMeta": {
                "properties": {
                    "total": {
                        "type": "number",
                        "format": "double"
                    }
                },
                "required": [
                    "total"
                ],
                "type": "object",
                "additionalProperties": false
            },
            "ApiResponseList_Project_": {
                "properties": {
                    "data": {
                        "items": {
                            "$ref": "#/components/schemas/Project"
                        },
                        "type": "array"
                    },
                    "errors": {
                        "items": {
                            "$ref": "#/components/schemas/ApiInternalError"
                        },
                        "type": "array"
                    },
                    "meta": {
                        "$ref": "#/components/schemas/ApiResponseListMeta"
                    }
                },
                "required": [
                    "data",
                    "errors"
                ],
                "type": "object",
                "additionalProperties": false
            },
            "ApiResponse_Project_": {
                "properties": {
                    "data": {
                        "$ref": "#/components/schemas/Project"
                    },
                    "errors": {
                        "items": {
                            "$ref": "#/components/schemas/ApiInternalError"
                        },
                        "type": "array"
                    },
                    "meta": {
                        "type": "number",
                        "enum": [
                            null
                        ],
                        "nullable": true
                    }
                },
                "required": [
                    "data",
                    "errors"
                ],
                "type": "object",
                "additionalProperties": false
            },
            "ProjectCreateParams": {
                "properties": {
                    "name": {
                        "type": "string"
                    }
                },
                "required": [
                    "name"
                ],
                "type": "object",
                "additionalProperties": false
            }
        },
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "JWT"
            }
        }
    },
    "info": {
        "title": "projects-api",
        "version": "1.0.0",
        "description": "Projects backend for frontend",
        "license": {
            "name": "ISC"
        },
        "contact": {}
    },
    "paths": {
        "/v1/projects": {
            "get": {
                "operationId": "GetProjects",
                "responses": {
                    "200": {
                        "description": "Ok",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ApiResponseList_Project_"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": []
            },
            "post": {
                "operationId": "CreateProject",
                "responses": {
                    "201": {
                        "description": "Created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ApiResponse_Project_"
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": [],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/ProjectCreateParams"
                            }
                        }
                    }
                }
            }
        }
    },
    "servers": [
        {
            "url": "/projects-api"
        }
    ]
}

Expected behavior TSC should not error on generated files

Screenshots

image

Additional context Add any other context about the problem here.

7nohe commented 5 months ago

@sourceful-mia I tried the spec file provided in the following repository, and there were no errors. Are there any other options needed?

https://github.com/7nohe/orqc-repro-118