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

[BUG] TypeScript (fetch) client does not build using 7.5.0

Open falk-stefan opened this issue 1 year ago • 1 comments

Maybe this is not a bug, but I thought I'd raise the issue in case it is.

Note: My solution was to set the CLI version to 7.4.0 for now but, as it would seem, 7.5.0 is somehow introducing a breaking change for me.

I am using the opanepi-generator-cli in my CI/CD pipeline and recently I learned, that I should have hard-set the version as I implemented it.

My pipeline started off with 7.3.0 and also worked with 7.4.0. I didn't notice when 7.5.0 got released which is where my pipeline broke.

With 7.5.0 I'd get the following compilation errors as I try to build and publish the npm package:

2024-04-20T19:00:33.6346556Z > tsc
2024-04-20T19:00:33.6347141Z 
2024-04-20T19:00:36.1628404Z ##[error]src/models/MediaStatus.ts(30,19): error TS2550: Property 'values' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.
2024-04-20T19:00:36.1642930Z ##[error]src/models/MediaType.ts(28,19): error TS2550: Property 'values' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.
2024-04-20T19:00:36.1649009Z ##[error]src/models/ReviewAction.ts(28,19): error TS2550: Property 'values' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.
2024-04-20T19:00:36.1654902Z ##[error]src/models/TourStatus.ts(29,19): error TS2550: Property 'values' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.
2024-04-20T19:00:36.1661272Z ##[error]src/models/TourStopType.ts(28,19): error TS2550: Property 'values' does not exist on type 'ObjectConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2017' or later.

Generated files

Here is an example for one of the generated files MediaType:

/* tslint:disable */
/* eslint-disable */
/**
 * backend-sequelize
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.0.1
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


/**
 * 
 * @export
 */
export const MediaType = {
    Audio: 'audio',
    Video: 'video'
} as const;
export type MediaType = typeof MediaType[keyof typeof MediaType];


export function instanceOfMediaType(value: any): boolean {
    return Object.values(MediaType).includes(value);
}

export function MediaTypeFromJSON(json: any): MediaType {
    return MediaTypeFromJSONTyped(json, false);
}

export function MediaTypeFromJSONTyped(json: any, ignoreDiscriminator: boolean): MediaType {
    return json as MediaType;
}

export function MediaTypeToJSON(value?: MediaType | null): any {
    return value as any;
}

package.json

{
  "name": "@my-projectr/api-client",
  "version": "v0.0.1",
  "description": "OpenAPI client for @my-project/api-client",
  "author": "OpenAPI-Generator",
  "repository": {
    "type": "git",
    "url": "https://github.com/git://github.com/my-project/my-project.git.git"
  },
  "main": "./dist/index.js",
  "typings": "./dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "prepare": "npm run build"
  },
  "devDependencies": {
    "typescript": "^4.0"
  },
  "publishConfig": {
    "registry": "git://github.com/my-project/my-project.git"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "lib": [
      "es6",
      "dom"
    ],
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "exclude": [
    "dist",
    "node_modules"
  ]
}

Logging

Here's the initial log-lines from the run using 7.5.0:

$ npm run client:ts

> [email protected] client:ts
> npm run swagger:gen && openapi-generator-cli generate -g typescript-fetch -i doc/swagger.yaml -o .clients/api-client -c openapitools.json


> [email protected] swagger:gen
> tsoa spec-and-routes --yaml

Download 7.5.0 ...
Downloaded 7.5.0
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: typescript-fetch (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'typescript-fetch' is considered stable.
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Note: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN  o.o.codegen.DefaultCodegen - The value (generator's option) must be either boolean or string. Default to `false`.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as UploadTourCoverImage_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings UploadTourCoverImage_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings UploadTourCoverImage_request=NewModel,ModelA=NewModelA in CLI).
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.DefaultGenerator - Model UploadTourCoverImage_request not generated since it's marked as unused (due to form parameters) and `skipFormModel` (global property) set to true (default)

Please close this issue in case this is an expected breaking change. Let me know if I can provide further information. Unfortunately I do lack the time at the moment to further investigage which means I'll just go with 7.4.0 but perhaps somebody ends up with a similar issue.

falk-stefan avatar Apr 21 '24 08:04 falk-stefan

It seems that this bug has been fixed in 7.6.0. I got a broken build in 7.5.0, but it works in 7.6.0.

Bogay avatar May 23 '24 12:05 Bogay