OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript] Using OneOf does not work as expected
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?
Description
Using openapigenerator 6.0.1, with generator "typescript".
If a spec uses oneOf (Case 1), the members of oneOf get mashed together properties. This deviates from the expected behaviour, which is that we should see a union type ({ ...aProps } | { ...bProps }).
In addition (Case 2), if a member of oneOf uses allOf to specify an ancestor, that ancestor's properties will be pulled in, but the child's won't. This bug is probably equivalent to https://github.com/OpenAPITools/openapi-generator/issues/13417.
Expected type for ExamplepathGet200Response in case 1:
{ childAttribute: string } | { otherChildAttribute: string }
Actual type for ExamplepathGet200Response in case 1:
{ childAttribute: string, otherChildAttribute: string }
Expected type for ExamplepathGet200Response in case 2:
{ parentAttribute: string, childAttribute: string } | { parentAttribute: string, otherChildAttribute: string }
Actual type for ExamplepathGet200Response in case 2:
{ parentAttribute: string }
openapi-generator version
6.0.1
OpenAPI declaration file content or url
Case 1: https://gist.github.com/MattiasMartens/e9378fedc79992c0bd6acc7b6783e2dc
Case 2: https://gist.github.com/MattiasMartens/e9378fedc79992c0bd6acc7b6783e2dc
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
Run the TypeScript generator against the two OpenAPI declarations linked in the report and compare the generated ExamplepathGet200Response types with the expected unions. The fix is complete when direct oneOf members remain a union and allOf ancestors retain each child’s properties in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100