OpenAPITools / OpenAPITools/openapi-generator
[BUG] Error generating TypeScript when request body includes discriminated union
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)? (used Redocly struct linter)
- 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
Spec with a discriminated union in a request produces error:
[main] ERROR o.o.codegen.DefaultCodegen - Error in generating
examplefor the property SchemaForRequestBodyApplicationJson. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.
openapi-generator version
7.12.0
OpenAPI declaration file content or url
Link to minimum reproducible spec
Generation Details
I've put up a full reproduction at https://github.com/collinsauve/testing-openapi-generator-cli that includes the above linked spec and a few others that demonstrate a bit more of the problem space.
Without using that, the command is:
npx @openapitools/openapi-generator-cli generate -g typescript -i "spec.yaml" -o "output"
Steps to reproduce
- Clone https://github.com/collinsauve/testing-openapi-generator-cli
- Run
bin/test test3-union-with-two-types
Related issues/PRs
- Same error as https://github.com/OpenAPITools/openapi-generator/issues/8663
- Originally reported via https://github.com/planet-a-ventures/affinity-node/pull/70 by @joscha in when using this generator on one of our (Affinity.co's) specs.
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
Start by running the bin/test test3-union-with-two-types reproduction from the linked repository, or invoke the TypeScript generator with the linked test3-union-with-two-types.yaml spec. Trace the DefaultCodegen example-generation error and compare the generated output with the expected handling of the discriminated union; done means generation completes without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100