hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
626 stars 44 forks source link

Schema with a number-only name gets generated into uncompilable code #645

Open kostia1st opened 3 weeks ago

kostia1st commented 3 weeks ago

Description

Having a schema like this

{
    "components": {
        "schemas": {
            "400": {
                "type": "object",
                "required": [
                    "code",
                    "message"
                ],
                "properties": {
                    "code": {
                        "type": "string",
                        "description": "Error code"
                    },
                    "message": {
                        "type": "string",
                        "description": "User-readable message"
                    },
                    "invalidFields": {
                        "type": "object",
                        "description": "Invalid fields",
                        "additionalProperties": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "object",
                                    "additionalProperties": {
                                        "type": "string"
                                    }
                                }
                            ],
                            "description": "Field name as key"
                        }
                    }
                }
            }
        }
}

I get this

export type  = {
    /**
     * Error code
     */
    code: string;
    /**
     * User-readable message
     */
    message: string;
    /**
     * Invalid fields
     */
    invalidFields?: {
        [key: string]: (string | {
    [key: string]: (string);
});
    };
};

Config:

createClient({
  client: '@hey-api/client-fetch', // This one does NOT camelize query parameters
  input: './openapi.json',
  output: './openapi-temp',
  exportCore: false,
  schemas: false,
  types: { name: 'PascalCase' },
});

OpenAPI specification (optional)

No response

Configuration

createClient({
  client: '@hey-api/client-fetch', // This one does NOT camelize query parameters
  input: './openapi.json',
  output: './openapi-temp',
  exportCore: false,
  schemas: false,
  types: { name: 'PascalCase' },
});

System information (optional)

No response

mrlubos commented 3 weeks ago

This looks more like an issue with the name itself, type is a reserved word. I'll have a look