OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] `Module '"./MyEnum"' has no exported member 'instanceOfMyEnum'.` and `Spread types may only be created from object types.`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
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
- https://github.com/OpenAPITools/openapi-generator/issues/14611
- https://github.com/OpenAPITools/openapi-generator/issues/14763
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided CLI command and OpenAPI schema, then inspect the generated models/MyModel.ts and MyEnum.ts files for the missing export and invalid spread. Compare the output with openapi-generator 5.4.0 and later versions; done means the generated TypeScript compiles without TS2305 or TS2698 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100