Skip to content

Commit fec0a09

Browse files
authored
Ensure anyOf preserves primitive types (#1380)
1 parent 339a167 commit fec0a09

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.changeset/primitive-anyof-test.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"swagger-typescript-api": patch
3+
---
4+
5+
Add test verifying primitive + object anyOf unions.

tests/spec/object-types/__snapshots__/basic.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ export type Test1 = {
6060
multiple: string | number;
6161
} | null;
6262
63+
export interface AddressCreationRequest {
64+
city?: string;
65+
}
66+
67+
export interface ContainerWithPrimitiveAnyOf {
68+
origin?: string | AddressCreationRequest;
69+
}
70+
6371
export interface AdditionalObjectProperties {
6472
id?: string;
6573
[key: string]: any;

tests/spec/object-types/schema.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@
8383
}
8484
}
8585
},
86+
"AddressCreationRequest": {
87+
"type": "object",
88+
"properties": {
89+
"city": {
90+
"type": "string"
91+
}
92+
}
93+
},
94+
"ContainerWithPrimitiveAnyOf": {
95+
"type": "object",
96+
"properties": {
97+
"origin": {
98+
"anyOf": [
99+
{
100+
"type": "string"
101+
},
102+
{
103+
"$ref": "#/definitions/AddressCreationRequest"
104+
}
105+
]
106+
}
107+
}
108+
},
86109
"AdditionalObjectProperties": {
87110
"type": "object",
88111
"properties": {

0 commit comments

Comments
 (0)