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.48k stars 6.5k forks source link

[BUG] [typescript-fetch] `Module '"./MyEnum"' has no exported member 'instanceOfMyEnum'.` and `Spread types may only be created from object types.` #15473

Open eliw00d opened 1 year ago

eliw00d commented 1 year ago

Bug Report Checklist

Description

My CLI:

yarn g:openapi-generator-cli generate -i ./api-docs.yaml -g typescript-fetch -o ./src --additional-properties=supportsES6=true,disallowAdditionalPropertiesIfNotPresent=false

My Schema:

components:
  schemas:
    MyEnum:
      type: string
      enum:
      - ONE
      - TWO
      - THREE
      - FOUR
      - FIVE
      - ETC
    MyObject:
      type: object
      properties:
        type:
          nullable: true
          oneOf:
          - $ref: '#/components/schemas/MyEnum'

Error that happens because certain files are expecting to use instanceOfMyEnum - which does not exist:

models/MyModel.ts:17:5 - error TS2305: Module '"./MyEnum"' has no exported member 'instanceOfMyEnum'.

17     instanceOfMyEnum,
       ~~~~~~~~~~~~~~~~~~~~~~~

Error that happens because certain files are expecting to spread the result of MyEnumFromJSONTyped(json, true):

models/MyModel.ts:38:14 - error TS2698: Spread types may only be created from object types.

38     return { ...MyEnumFromJSONTyped(json, true) };
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
openapi-generator version

TS2305 errors occur on: >=6.1.0 TS2698 errors occur on >=6.0.0

Neither occur on 5.4.0.

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
eliw00d commented 1 year ago

I found https://github.com/OpenAPITools/openapi-generator/issues/14611 which pointed out that the instanceOf errors would go away by downgrading to 6.0.0. I tried that and it does get rid of those errors, but I am still left with the spread types errors.

eliw00d commented 1 year ago

I also downgraded to 5.4.0 and no longer see this issues, so at least there is a workaround.

giovannicimolin commented 6 months ago

@eliw00d I think I have a fix for this on this PR: https://github.com/OpenAPITools/openapi-generator/pull/18154.

Can you test using that branch to see if your problem is fixed?

eliw00d commented 6 months ago

@eliw00d I think I have a fix for this on this PR: #18154.

Can you test using that branch to see if your problem is fixed?

I tried building from your branch but got:

Failed to execute goal org.fortasoft:gradle-maven-plugin:1.0.8:invoke (default) on project openapi-generator-gradle-plugin-mvn-wrapper: org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.7-bin.zip'

Which, according to the docs, there is no solution for.