OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] `oneOf` containing `enum` tries to import nonexistent instanceOf function
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
Using a schema with a oneOf component containing enums leads to leads to broken code where the type tries to import instanceOf functions that aren't generated for enums.
openapi-generator version
6.2.1 and 6.3.0.
OpenAPI declaration file content or url
JSON
{
"openapi": "3.0.0",
"info": { "title": "Foo", "version": "1.0.0" },
"servers": [],
"paths": {},
"components": {
"schemas": {
"Timezone": {
"oneOf": [
{
"description": "(UTC-12:00) International Date Line West",
"type": "string",
"enum": [
"DatelineStandardTime"
]
},
{
"description": "(UTC-11:00) Coordinated Universal Time-11",
"type": "string",
"enum": [
"UtcMinus11"
]
},
{
"description": "(UTC-10:00) Aleutian Islands",
"type": "string",
"enum": [
"AleutianStandardTime"
]
}
]
}
}
}
}
Generation Details
yarn openapi-generator-cli generate \
--input-spec {{OPENAPI_SPEC}} \
--generator-name typescript-fetch \
--output ./src/api \
--additional-properties \
"supportsES6=true,\
withInterfaces=true,\
enumNameSuffix=,\
enumPropertyNaming=UPPERCASE,\
modelPropertyNaming=camelCase,\
typescriptThreePlus=true,\
stringEnums=true\
"
Steps to reproduce
- Write the schema to a file.
- Run the code
typescript-fetchgenerator - Try to compile the generated typescript files
- It fails because the type tries to import e.g.
instanceOfTimezoneOneOfwhich doesn't exist.
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
Start by running the provided OpenAPI schema through the typescript-fetch generator with the listed options, then compile the generated TypeScript files. Trace the generated Timezone oneOf model and its enum variants to find where the nonexistent instanceOfTimezoneOneOf import is introduced. Done means the same schema generates TypeScript that compiles without that import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100