openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
Using `oneOf` and `properties` generates incorrect code
Describe the bug
Using oneOf and properties treats properties as another oneOf case, instead of merging these fields in.
"ComposedSchema": {
"type": "object",
"oneOf": [
{
"type": "object",
"required": [
"data1"
],
"properties": {
"data1": {
"$ref": "#/components/schemas/MySchema1"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"data2"
],
"properties": {
"data2": {
"$ref": "#/components/schemas/MySchema2"
}
},
"additionalProperties": false
}
],
"required": [
"field1",
"field2"
],
"properties": {
"field1": {
"type": "integer",
"format": "uint16",
"minimum": 0.0
},
"field2": {
"type": "integer",
"format": "uint8",
"minimum": 0.0,
"nullable": true
}
}
},
Generates:
export type ComposedSchema =
| {
data1: MySchema1;
}
| {
data2: MySchema2;
}
| {
field1: number;
field2?: number | null;
};
But should generate:
export type ComposedSchema =
| {
data1: MySchema1;
field1: number;
field2?: number | null;
}
| {
data2: MySchema2;
field1: number;
field2?: number | null;
};
The generator still works using the nullable: true key. This is a workaround, especially if you want to use OpenAPI 3.1
@MattGson I got this use case fixed in our fork which aims to support OpenAPI 3.1. Would you mind giving it a try and see if it works for you?