You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] [TypeScript-Axios] invalid code generation of anyOf #12432
What it should be (this is the original defiinitoin on our side)
But what it does:
so it's not purchasedPackageId OR packageId.. it is an AND.
It's the same if we use it without the "mode" paramter, then it's just merged into one (so also purchasedPackageId and packageId is required, instead of an OR).
openapi-generator version
6.0.0 - latest master snapshot
did work with 5.x
OpenAPI declaration file content or url
Reacted by Max Komarychev, sergeykhealth, Liron Sher, Mor Shemesh, matt7aylor, Andrey Starostin, Sebastien Guillemot, Winnie, David Browne, Patrick Kerschbaum and 1 more
This rejects the invalid array, but is not a contract-equivalent workaround: integer and number overlap, whereas oneOf requires exactly one matching alternative. The generated union also excludes null; the intended nullability and its correct OpenAPI representation need to be covered explicitly by the regression tests.
Our reproducible evaluation is available in LibreSign/libresign#9437. We have reproduced this on the released versions above, but have not yet tested the current upstream master or those PR branches against our contract.
We would like to investigate an upstream Axios fix, with regression tests for mixed primitive/object alternatives and nullability, potentially using #25394 as a reference. Would you prefer this work to remain tracked here, or should we open a separate issue for this specific case?
Activity
simllll commentedon May 23, 2022
Update: it "works" in earlier versions only because it's generated to a generic "object":

spacether commentedon Jun 16, 2022
What generator are you using?
simllll commentedon Jun 16, 2022
axios-typescript
That's the command line:
ikopysov commentedon Sep 7, 2022
Can this issue be renamed to avoid confusion? There are multiple clients with this issue and I belive all of them should be fixed individually.
This can be renamed to
(most used in the issues page)
or
(kind of easier to find for axios users, but harder for TypeScript users)
123FLO321 commentedon Sep 8, 2022
I am pretty sure that this issue affects all typescript generators.
[-][BUG] invalid code generation of anyOf[/-][+][BUG] [TypeScript-Axios] invalid code generation of anyOf[/+]bintoll commentedon Sep 21, 2022
I also face this issue. The generated code is invalid with anyOf
vpishuk commentedon Dec 11, 2022
I have the same issue with this generator.
Any of generates this file:
You can try to use
oneOfas a workaround. It will work in the same way, but slightly slower.vpishuk commentedon Dec 11, 2022
I mad an MR to fix this issue.
#14241
Naktibalda commentedon Jul 24, 2023
I noticed that
anyOfgenerator fails in 2 different ways:generates empty interface:
combines all properties to single interface as described in original issue.
Naktibalda commentedon Jul 25, 2023
I changed all
anyOfkeywords tooneOfin my specification and openapi-generator produced expected types.binhtran04 commentedon Sep 26, 2023
I have the same issue:
anyOf generates an empty interface, while oneOf correctly generates a Union
Not sure if it's safe to change all
anyOftooneOflfals commentedon Nov 12, 2026
We encountered the empty-interface variant of this issue while evaluating
typescript-axiosfor LibreSign.With OpenAPI Generator 7.15.0 and 7.27.0, using
useSingleRequestParameter=true, this schema from our OpenAPI contract generates an empty interface:Actual output:
Consequently, this invalid value compiles under strict TypeScript:
At minimum, the generated type should preserve the declared alternatives and reject arrays, instead of widening the model to an empty interface.
We also tested replacing
anyOfwithoneOfin a disposable generator-input copy only. That generates:This rejects the invalid array, but is not a contract-equivalent workaround:
integerandnumberoverlap, whereasoneOfrequires exactly one matching alternative. The generated union also excludesnull; the intended nullability and its correct OpenAPI representation need to be covered explicitly by the regression tests.Related work we found:
generateAnyOfAsUnionfor typescript-fetch.Our reproducible evaluation is available in LibreSign/libresign#9437. We have reproduced this on the released versions above, but have not yet tested the current upstream master or those PR branches against our contract.
We would like to investigate an upstream Axios fix, with regression tests for mixed primitive/object alternatives and nullability, potentially using #25394 as a reference. Would you prefer this work to remain tracked here, or should we open a separate issue for this specific case?