Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] v7.0.0 typescript-axios generator generates export interface ProtobufAny different from v6.6.0 #16494

Closed
4 of 6 tasks
tony95271 opened this issue Sep 4, 2023 · 6 comments · Fixed by #17625
Closed
4 of 6 tasks

Comments

@tony95271
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

v6.6.0 generates what we and tsc expected, v7.0.0 doesn't.

openapi-generator version

v7.0.0

OpenAPI declaration file content or url

swagger spec file t.json

{
  "swagger": "2.0",
  "info": {
    "title": "foo APIs",
    "version": "0.0.1"
  },
  "host": "foo.com",
  "paths": {
    "/hello": {}
  },
  "definitions": {
    "protobufAny": {
      "type": "object",
      "properties": {
        "@type": {
          "type": "string"
        }
      },
      "additionalProperties": {}
    }
  }
}

openapi tool configuration file foo.openapitools.json

{
  "npmName": "foo",
  "npmVersion": "0.0.1",
  "snapshot": false,
  "supportsES6": true,
  "modelPropertyNaming": "original"
}
Generation Details
Steps to reproduce

generate code from spec

openapi-generator-cli version-manager set 7.0.0
openapi-generator-cli generate -i t.json --generator-name typescript-axios -o src/gen/foo -c foo.openapitools.json

tsc build failed with v7.0.0

npm run --prefix src/gen/foo build                                                                                

> [email protected] build
> tsc && tsc -p tsconfig.esm.json

api.ts:39:5 - error TS2411: Property ''@type'' of type 'string' is not assignable to 'string' index type 'object'.

39     '@type'?: string;
       ~~~~~~~


Found 1 error in api.ts:39
Related issues/PRs
Suggest a fix

If we switch back to 6.6.0 everything works as expected:

openapi-generator-cli version-manager set 6.6.0

openapi-generator-cli generate -i t.json --generator-name typescript-axios -o src/gen/foo -c foo.openapitools.json
npm run --prefix src/gen/foo build

we diff v6.6.0 and v7.0.0

 diff -Nuar  src/gen/foo/api.ts /tmp/app/src/gen/foo/api.ts
--- src/gen/foo/api.ts	2023-09-04 13:39:42
+++ /tmp/app/src/gen/foo/api.ts	2023-09-04 13:39:57
@@ -29,7 +29,7 @@
  * @interface ProtobufAny
  */
 export interface ProtobufAny {
-    [key: string]: object | any;
+    [key: string]: object;
 
     /**
      * 
@wing328
Copy link
Member

wing328 commented Sep 4, 2023

thanks for reporting the issue. Do you mind doing a git bisect to identify the commit causing the change?

@wing328
Copy link
Member

wing328 commented Sep 6, 2023

looks like the change is introduced in https://github.com/OpenAPITools/openapi-generator/pull/16227/files#diff-63a9b6b47bf90864cbaba673df9dc3f390ecab6183e6b0608147921d7de42b16

i'll take a look this weekend to see if I restore the previous behaviour.

@wing328
Copy link
Member

wing328 commented Sep 7, 2023

    "protobufAny": {
      "type": "object",
      "properties": {
        "@type": {
          "type": "string"
        }
      },
      "additionalProperties": {}

ProtobufAny has one property @type. It looks to me the followings (both) are incorrect:

-    [key: string]: object | any;
+    [key: string]: object;

I tested with typescript client generator and got the following instead:

import { HttpFile } from '../http/http';

export class ProtobufAny {
    'type'?: string;

    static readonly discriminator: string | undefined = undefined;

    static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
        {
            "name": "type",
            "baseName": "@type",
            "type": "string",
            "format": ""
        }    ];

    static getAttributeTypeMap() {
        return ProtobufAny.attributeTypeMap;
    }

    public constructor() {
    }
}

Should this be the correct output instead?

@tony95271
Copy link
Author

https://github.com/OpenAPITools/openapi-generator/pull/16227/files#diff-63a9b6b47bf90864cbaba673df9dc3f390ecab6183e6b0608147921d7de42b16

This change is too big to understand. :(

Should this be the correct output instead?

I'm not sure, why not try my steps to reproduce?
t.json and foo.openapitools.json are very small but it could reproduce the bug.

@luisaugusto
Copy link

I'm running into the same issue, with v7, the index signature for one of my generated interfaces is being changed from [key: string]: string | any; to [key: string]: string; with this schema:

{
    type: 'object',
    example: 'ok',
    additionalProperties: {
        type: 'object',
        properties: {
            status: {
                type: 'string',
            },
        },
        additionalProperties: {
            type: 'string',
        },
    },
}

Generated interface:

export interface HealthCheckControllerCheck200ResponseInfoValue {
    [key: string]: string;

    /**
     * 
     * @type {string}
     * @memberof HealthCheckControllerCheck200ResponseInfoValue
     */
    'status'?: string;
}

Causing the error TS2411: Property  'status'  of type  string | undefined  is not assignable to  string  index type  string 

I downgraded to v6.6 and everything works fine.

@vikramparth
Copy link

Any updates on when this bug might be fixed? It's preventing us from upgrading to v7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment