hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
Other
995 stars 82 forks source link

Interfaces generated with unmatched closing parenthesis when run in GitLab Pipeline #966

Open rdecoito opened 3 weeks ago

rdecoito commented 3 weeks ago

Description

(Using openapi-ts version 0.52.9 "@hey-api/openapi-ts": "~0.52.0")

Weird problem to have run into, but I've currently got a monorepo setup (using Rush) where one of my packages uses openapi-ts to generate a client. We don't commit our generated client and instead generate it each time the pipeline runs, then use that generated code to run tests and build everything.

Everything works perfectly fine when I'm running everything locally, but for some reason when the openapi-ts command is run in our GitLab pipeline, it generates a borked types.gen.ts where some of the Response data types (interfaces) have a closing parenthesis that causes syntax errors. I discovered this while I was running my test command and got the following error:

Error: Transform failed with 1 error:
/builds/<company>/<project>/website/apps/@<company>/<package-name>/src/<ClientFolderName>/types.gen.ts:1195:1: ERROR: Unexpected ")"

I was confused why it was getting that error because when I checked that line locally there was no ) character. But then I went into the job's artifacts and downloaded its types.gen.ts file and saw the following plain as day:

export interface NotificationSourcesResponse {
    [key: string]: NotificationSourceInfo;
});

Notice the closing parenthesis at the end, as if this were supposed to be a type declaration but the second paren wasn't removed.

For context, here is an excerpt from the openapi.json input file that shows the related endpoint:

"/notification-sources": {
    "get": {
        "tags": [
            "Notification"
        ],
        "summary": "Returns a dictionary mapping notification source names to their info",
        "description": "Get available notification sources supported",
        "operationId": "notification_sources",
        "responses": {
            "200": {
                "description": "Successful Response",
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "object",
                            "additionalProperties": {
                                "$ref": "#/components/schemas/NotificationSourceInfo"
                            },
                            "title": "Response Notification Sources"
                        }
                    }
                }
            }
        }
    }
},

And here's that NotificationSourceInfo schema from the same file:

"NotificationSourceInfo": {
    "properties": {
        "source": {
            "type": "string",
            "title": "Source"
        },
        "pretty": {
            "type": "string",
            "title": "Pretty"
        },
        "notification_info": {
            "type": "string",
            "title": "Notification Info"
        }
    },
    "type": "object",
    "required": [
        "source",
        "pretty",
        "notification_info"
    ],
    "title": "NotificationSourceInfo",
    "description": "<description text removed for brevity>"
},

And here's my openapi-ts.config.ts (the generate command was run without any options, simply openapi-ts):

import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
    client: 'fetch',
    input: './<project>-openapi.json',
    output: {
        path: './src/<ClientFolderName>/',
        format: 'prettier',
        lint: 'eslint'
    },
    services: {
        asClass: true
    },
    types: {
        enums: 'typescript'
    },
    schemas: false
});

Big Question

Do you have any idea what might be causing this parenthesis? The above Response data type is not the only one to have this problem. A ctrl+F in types.gen.ts is giving 83 instances of this error, and they are all typescript interfaces with the suffix Response in their name, indicating they are all types generated by a defined schema in the openapi.json file associated with the output of a particular endpoint.

I want to stress again I do not see this problem locally, so there must be some kind of weird environment or config problem while the code is running in the gitlab pipeline, but I have no idea where to look to get any information about the root cause. Any ides?

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example

OpenAPI specification (optional)

No response

System information (optional)

No response

stackblitz[bot] commented 3 weeks ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

mrlubos commented 3 weeks ago

@rdecoito suspicious indeed, thanks for reporting! Will look into it