File tree Expand file tree Collapse file tree 4 files changed +122
-0
lines changed Expand file tree Collapse file tree 4 files changed +122
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,14 @@ export function resolve (
160
160
const subjectType = type . getTypeArguments ( ) [ 0 ] ?? type . getAliasTypeArguments ( ) [ 0 ]
161
161
const name = type . getSymbol ( ) ?. getEscapedName ( ) !== '__type' ? type . getSymbol ( ) ?. getEscapedName ( ) : helperName
162
162
typeName = `${ name } _${ retrieveTypeName ( subjectType ) } `
163
+ } else if ( ( type . getAliasTypeArguments ( ) . length === 1 || type . getTypeArguments ( ) . length === 1 ) && ( type . getTypeArguments ( ) [ 0 ] ?? type . getAliasTypeArguments ( ) [ 0 ] ) ?. isUnion ( ) === true ) { // i.e. Serialized<WorkerDatasource | ProxyDatasource> -> Serialized_Union_WorkerDatasource_ProxyDatasource
164
+ const subjectType = type . getTypeArguments ( ) [ 0 ] ?? type . getAliasTypeArguments ( ) [ 0 ]
165
+ const name = type . getSymbol ( ) ?. getEscapedName ( ) !== '__type' ? type . getSymbol ( ) ?. getEscapedName ( ) : helperName
166
+ typeName = `${ name } _Union_${ subjectType . getUnionTypes ( ) . map ( t => retrieveTypeName ( t ) ) . join ( '_' ) } `
167
+ } else if ( ( type . getAliasTypeArguments ( ) . length === 1 || type . getTypeArguments ( ) . length === 1 ) && ( type . getTypeArguments ( ) [ 0 ] ?? type . getAliasTypeArguments ( ) [ 0 ] ) ?. isIntersection ( ) === true ) { // i.e. Serialized<WorkerDatasource & ProxyDatasource> -> Serialized_Intersection_WorkerDatasource_ProxyDatasource
168
+ const subjectType = type . getTypeArguments ( ) [ 0 ] ?? type . getAliasTypeArguments ( ) [ 0 ]
169
+ const name = type . getSymbol ( ) ?. getEscapedName ( ) !== '__type' ? type . getSymbol ( ) ?. getEscapedName ( ) : helperName
170
+ typeName = `${ name } _Intersection_${ subjectType . getIntersectionTypes ( ) . map ( t => retrieveTypeName ( t ) ) . join ( '_' ) } `
163
171
} else if ( isTypeIdentifier ( type ) === false ) { // For other and anonymous types, don't use ref
164
172
return resolveObjectType ( type , spec )
165
173
}
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ type SuccessResponse<T extends any> = { data: T }
5
5
type Entity = {
6
6
name : string
7
7
}
8
+ type Entity2 = {
9
+ name : number
10
+ }
8
11
9
12
@Route ( '/my-3nd-controller/' )
10
13
@Security ( { company : [ ] } )
@@ -13,6 +16,14 @@ export class My3ndController {
13
16
public async list ( ) : Promise < SuccessResponse < Entity [ ] > > {
14
17
return { data : [ { name : 'foo' } ] }
15
18
}
19
+ @Get ( '/example' )
20
+ public async getIntersection ( ) : Promise < SuccessResponse < Entity & { example : string } > > {
21
+ return { data : { name : 'foo' , example : '' } }
22
+ }
23
+ @Get ( '/union' )
24
+ public async getUnion ( ) : Promise < SuccessResponse < Entity | Entity2 > > {
25
+ return { data : { name : 'foo' } }
26
+ }
16
27
@Post ( '/' )
17
28
public async create ( ) : Promise < SuccessResponse < Entity > > {
18
29
return { data : { name : 'foo' } }
Original file line number Diff line number Diff line change @@ -82,6 +82,54 @@ Generated by [AVA](https://avajs.dev).
82
82
],␊
83
83
"operationId": "Update"␊
84
84
}␊
85
+ },␊
86
+ "/my-3nd-controller/example": {␊
87
+ "get": {␊
88
+ "parameters": [],␊
89
+ "responses": {␊
90
+ "200": {␊
91
+ "description": "Ok",␊
92
+ "content": {␊
93
+ "application/json": {␊
94
+ "schema": {␊
95
+ "$ref": "#/components/schemas/SuccessResponse_Intersection_Entity_example-string"␊
96
+ }␊
97
+ }␊
98
+ }␊
99
+ }␊
100
+ },␊
101
+ "tags": [],␊
102
+ "security": [␊
103
+ {␊
104
+ "company": []␊
105
+ }␊
106
+ ],␊
107
+ "operationId": "GetIntersection"␊
108
+ }␊
109
+ },␊
110
+ "/my-3nd-controller/union": {␊
111
+ "get": {␊
112
+ "parameters": [],␊
113
+ "responses": {␊
114
+ "200": {␊
115
+ "description": "Ok",␊
116
+ "content": {␊
117
+ "application/json": {␊
118
+ "schema": {␊
119
+ "$ref": "#/components/schemas/SuccessResponse_Union_Entity_Entity2"␊
120
+ }␊
121
+ }␊
122
+ }␊
123
+ }␊
124
+ },␊
125
+ "tags": [],␊
126
+ "security": [␊
127
+ {␊
128
+ "company": []␊
129
+ }␊
130
+ ],␊
131
+ "operationId": "GetUnion"␊
132
+ }␊
85
133
}␊
86
134
},␊
87
135
"components": {␊
@@ -111,6 +159,61 @@ Generated by [AVA](https://avajs.dev).
111
159
"data"␊
112
160
]␊
113
161
},␊
162
+ "SuccessResponse_Intersection_Entity_example-string": {␊
163
+ "type": "object",␊
164
+ "properties": {␊
165
+ "data": {␊
166
+ "allOf": [␊
167
+ {␊
168
+ "$ref": "#/components/schemas/Entity"␊
169
+ },␊
170
+ {␊
171
+ "type": "object",␊
172
+ "properties": {␊
173
+ "example": {␊
174
+ "type": "string"␊
175
+ }␊
176
+ },␊
177
+ "required": [␊
178
+ "example"␊
179
+ ]␊
180
+ }␊
181
+ ]␊
182
+ }␊
183
+ },␊
184
+ "required": [␊
185
+ "data"␊
186
+ ]␊
187
+ },␊
188
+ "Entity2": {␊
189
+ "type": "object",␊
190
+ "properties": {␊
191
+ "name": {␊
192
+ "type": "number"␊
193
+ }␊
194
+ },␊
195
+ "required": [␊
196
+ "name"␊
197
+ ]␊
198
+ },␊
199
+ "SuccessResponse_Union_Entity_Entity2": {␊
200
+ "type": "object",␊
201
+ "properties": {␊
202
+ "data": {␊
203
+ "oneOf": [␊
204
+ {␊
205
+ "$ref": "#/components/schemas/Entity"␊
206
+ },␊
207
+ {␊
208
+ "$ref": "#/components/schemas/Entity2"␊
209
+ }␊
210
+ ]␊
211
+ }␊
212
+ },␊
213
+ "required": [␊
214
+ "data"␊
215
+ ]␊
216
+ },␊
114
217
"SuccessResponse_Entity": {␊
115
218
"type": "object",␊
116
219
"properties": {␊
You can’t perform that action at this time.
0 commit comments