openapi-generator-cli icon indicating copy to clipboard operation
openapi-generator-cli copied to clipboard

[BUG] typescript-fetch 6.0.1 template compile issues

Open organom opened this issue 3 years ago • 0 comments

🐛 Bug Report:

Describe the bug

When using latest typescript template with react app, the latest typescript template (6.0.1) has typescript issues, while 6.0.0 was ok.

Steps to Reproduce

Steps to reproduce the behavior:

  1. create test folder with the following files inside: package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "build": "./node_modules/typescript/bin/tsc",
    "generate:sdk": "./node_modules/.bin/openapi-generator-cli version-manager set 6.0.1 && ./node_modules/.bin/openapi-generator-cli generate -i openapi.yaml --additional-properties=modelPropertyNaming=original,paramNaming=original,enumPropertyNaming=original -g typescript-fetch"
  },
  "dependencies": {
    "@openapitools/openapi-generator-cli": "^2.5.1",
    "typescript": "^4.7.2"
  },
  "author": "",
  "license": "ISC"
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "exclude": ["node_modules", "**/*.test.ts"]
}

openapi.yaml

openapi: 3.0.1
info:
  title: Test
  description: Test
  version: "0.1"

tags:
  - name: Test
    description: test

security:
  - BearerToken: [ ]

paths:
  /test:
    get:
      operationId: get_test
      tags:
        - Test
      description: Retrieves a test
      responses:
        '200':
          description: Operation has completed successfully
  1. cd into test folder and run npm install
  2. run npm run generate:sdk && npm run build and confirm that errors are displayed
> [email protected] build
> ./node_modules/typescript/bin/tsc

runtime.ts:119:13 - error TS2532: Object is possibly 'undefined'.

119         if (response.status >= 200 && response.status < 300) {
                ~~~~~~~~

runtime.ts:119:39 - error TS2532: Object is possibly 'undefined'.

119         if (response.status >= 200 && response.status < 300) {
                                          ~~~~~~~~

runtime.ts:120:13 - error TS2322: Type 'Response | undefined' is not assignable to type 'Response'.
  Type 'undefined' is not assignable to type 'Response'.

120             return response;
                ~~~~~~~~~~~~~~~~

runtime.ts:122:33 - error TS2345: Argument of type 'Response | undefined' is not assignable to parameter of type 'Response'.
  Type 'undefined' is not assignable to type 'Response'.

122         throw new ResponseError(response, 'Response returned an error code');
                                    ~~~~~~~~

runtime.ts:205:31 - error TS2532: Object is possibly 'undefined'.

205                     response: response.clone(),
                                  ~~~~~~~~

runtime.ts:239:14 - error TS2415: Class 'FetchError' incorrectly extends base class 'Error'.
  Types of property 'cause' are incompatible.
    Type 'unknown' is not assignable to type 'Error | undefined'.

239 export class FetchError extends Error {
                 ~~~~~~~~~~


Found 6 errors in the same file, starting at: runtime.ts:119
  1. open package.json and change 6.0.1 to 6.0.0 in generate:sdk command
  2. run again npm run generate:sdk && npm run build and confirm no errors are displayed

Expected behavior

Should work like with version 6.0.0

Package System (please complete the following information):

  • @openapitools/openapi-generator-cli 2.5.1
  • typescript 4.7.2
  • nodejs 16.15.1
  • npm 8.13.2

organom avatar Jul 04 '22 20:07 organom