OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.56k stars 6.52k forks source link

[BUG] Docker: generation failed for Angular versions before 12 because of @types/node 18.13.0 update #14805

Open ssarkisy opened 1 year ago

ssarkisy commented 1 year ago

Bug Report Checklist

Description

We are using Docker image of openapi-generator-cli to generate TypeScript code for Angular 11.2.14. https://hub.docker.com/r/openapitools/openapi-generator-cli/tags

Till recent time everything worked fine, but with version 18.13.0 of @types/node it basically drops the support of Angular version before 12. https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/64262

Here is our generation script:

docker run --rm \
    -v $GENERATED_CODE_DIR:/generated-code \
    -v $SWAGGER_SPEC_DIR:/input-spec openapitools/openapi-generator-cli:v5.3.1 \
    generate -g typescript-angular \
    -i //input-spec/$SWAGGER_FILE_PREFIX-swagger.json \
    -o //generated-code \
    --additional-properties=ngVersion=11.2.14,npmName=api-client-$SWAGGER_FILE_PREFIX

We are using version 5.3.1, but the problem is also confirmed on 6.2.0 and 6.4.0

Here is the part of generated package-lock.json:

    "@types/node": {
      "version": "18.14.1",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-18.13.0.tgz",
      "integrity": "sha512-gC3TazRzGoOnoKAhUx+Q0t8S9Tzs74z7m0ipwGpSqQrleP14hKxP4/JUeEQcD3W1/aIpnWl8pHowI7WokuZpXg==",
      "dev": true
    },

And here the errors we're getting when trying to build the API code:

✖ Compiling TypeScript sources through NGC
ERROR: node_modules/@types/node/ts4.8/test.d.ts:612:34 - error TS1005: '?' expected.

612             : F extends abstract new (...args: any) => infer T
                                     ~~~
node_modules/@types/node/ts4.8/test.d.ts:613:17 - error TS1005: ':' expected.

613                 ? T
                    ~
node_modules/@types/node/ts4.8/test.d.ts:614:17 - error TS1005: ',' expected.

614                 : unknown,
                    ~
node_modules/@types/node/ts4.8/test.d.ts:617:34 - error TS1005: '?' expected.

617             : F extends abstract new (...args: infer Y) => any
                                     ~~~
node_modules/@types/node/ts4.8/test.d.ts:618:17 - error TS1005: ':' expected.

618                 ? Y
                    ~
node_modules/@types/node/ts4.8/test.d.ts:619:17 - error TS1005: ',' expected.

619                 : unknown[],
                    ~
node_modules/@types/node/ts4.8/test.d.ts:619:26 - error TS1005: ',' expected.

619                 : unknown[],
                             ~
node_modules/@types/node/ts4.8/test.d.ts:620:5 - error TS1109: Expression expected.

620     > {
        ~
node_modules/@types/node/ts4.8/test.d.ts:624:24 - error TS1005: ',' expected.

624         arguments: Args;
                           ~
node_modules/@types/node/ts4.8/test.d.ts:628:35 - error TS1005: ',' expected.

628         error: unknown | undefined;
                                      ~
node_modules/@types/node/ts4.8/test.d.ts:634:39 - error TS1005: ',' expected.

634         result: ReturnType | undefined;
                                          ~
node_modules/@types/node/ts4.8/test.d.ts:638:21 - error TS1005: ',' expected.

638         stack: Error;
                        ~
node_modules/@types/node/ts4.8/test.d.ts:643:19 - error TS1005: ',' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                      ~~~~~~~
node_modules/@types/node/ts4.8/test.d.ts:643:27 - error TS1005: ':' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                              ~~~~~~~~
node_modules/@types/node/ts4.8/test.d.ts:643:36 - error TS1005: ',' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                                       ~~~
node_modules/@types/node/ts4.8/test.d.ts:643:55 - error TS1005: '{' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                                                          ~~
node_modules/@types/node/ts4.8/test.d.ts:643:64 - error TS1005: ',' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                                                                   ~
node_modules/@types/node/ts4.8/test.d.ts:643:77 - error TS1005: ',' expected.

643         target: F extends abstract new (...args: any) => any ? F : undefined;
                                                                                ~
node_modules/@types/node/ts4.8/test.d.ts:647:22 - error TS1005: ',' expected.

647         this: unknown;
                         ~

Just a few days ago the @types/node version in generated package-lock.json was "18.11.19" and everything worked fine.

If we will try to generate an API for Angular 12.2 - there are no errors.

openapi-generator version

Docker image of version 5.3.1 https://hub.docker.com/layers/openapitools/openapi-generator-cli/v5.3.1/images/sha256-fd605a2b72f40d1491b128cab58bbcd82159a5accc4dd0f01024dac36262ccfc?context=explore

OpenAPI declaration file content or url

Any OpenAPI json/yaml file with TypeScript target using ngVersion=11.2.14. The content of the API itself is irrelevant.

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Use specific @types/node version for every Angular version supported.

krelianer commented 1 year ago

Encoutering the same issue using the maven plugin :

    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>5.1.0</version>

Edit: We have found a workaround, once the angular generated-sources are created 1- npm install 2- npm install @types/node@18.11.19 --save-dev 3- npm run build

helloworld121 commented 1 year ago

I am facing the same issue. (I am using the plugin version 5.2.0) It looks like everything was working last week :) :D