support nested any-of to use with openapi v3.1 type null
Hi there 👋🏻
Thanks @ferdikoomen for your amazing job on this library 🙏🏻
I've tried my best to implement support for nested anyOf in order to use the type null rework on open api specification v3.1.
It seems related to https://github.com/ferdikoomen/openapi-typescript-codegen/issues/1643.
I remain at your disposal for any feedback on the implementation.
I wish you a great day ☀️
Best regards ☮️
I have a nested anyOf within an oneOf. Like:
"SomeDto": {
"type": "object",
"properties": {
"value": {
"oneOf": [
{
"type": "integer",
"format": "int32"
},
{
"type": "string"
},
{
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
}
]
}
}
],
"nullable": true
}
},
"additionalProperties": false
},
The generated api code seems to ignore the AnyOf, and generates the type as:
export type SomeDto = {
value?: (number | string) | null;
};
instead of:
export type SomeDto = {
value?: (number | string | Array<number | string>) | null;
};
does this PR also fix this issue?
hey @PaulVrugt,
with this PR changes, it will generate:
export type SomeDto = {
value?: (number | string | Array<(string | number)>) | null;
};
you can check on your machine if you want:
git clone [email protected]:smarlhens/openapi-typescript-codegen.git
git checkout feat/support-nested-any-of
npm install
then add at the end of components.schemas inside test/spec/v3.json:
"SomeDto": {
"type": "object",
"properties": {
"value": {
"oneOf": [
{
"type": "integer",
"format": "int32"
},
{
"type": "string"
},
{
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
}
]
}
}
],
"nullable": true
}
}
}
and then run
npm run test:update
git diff
you will see that inside test/__snapshots__/index.spec.ts.snap, in line to be added, the export type of SomeDto will be equal to the first snippet I wrote.
Hi @smarlhens ,
so the short answer is yes right? :)
@ferdikoomen can we get this merged? We are running into this in our code
Hi @smarlhens ,
so the short answer is
yesright? :)
Yes 👍🏻