@@ -4,7 +4,6 @@ import { OpenAPITypesGuard } from './OpenAPITypesGuard';
4
4
import { IOpenAPI3 } from './v3/open-api' ;
5
5
import { IOpenAPI3Operation } from './v3/operation' ;
6
6
import { IOpenAPI3Reference } from './v3/reference' ;
7
- import { IOpenAPI3AllOfSchema } from './v3/schemas/all-of-schema' ;
8
7
import { IOpenAPI3EnumSchema } from './v3/schemas/enum-schema' ;
9
8
import { IOpenAPI3ObjectSchema } from './v3/schemas/object-schema' ;
10
9
import { OpenAPI3Schema , OpenAPI3SchemaContainer } from './v3/schemas/schema' ;
@@ -201,17 +200,11 @@ export class OpenAPIService {
201
200
refKeys . add ( ref . $ref ) ;
202
201
203
202
const schema = this . getSchemaByRef ( ref ) ;
204
- if ( this . typesGuard . isObject ( schema ) ) {
203
+ if ( schema ) {
205
204
const refsFromObject = this . getRefsByObject ( schema , ref ) ;
206
205
const expanded = this . expandRefs ( refsFromObject , refKeys ) ;
207
206
collectedRefs . push ( ...expanded ) ;
208
207
}
209
-
210
- if ( this . typesGuard . isAllOf ( schema ) ) {
211
- const refsFromObject = this . getRefsByAllOf ( schema , ref ) ;
212
- const expanded = this . expandRefs ( refsFromObject , refKeys ) ;
213
- collectedRefs . push ( ...expanded ) ;
214
- }
215
208
} ) ;
216
209
217
210
return collectedRefs ;
@@ -221,46 +214,29 @@ export class OpenAPIService {
221
214
* @description Gets refs from object schema only one level down
222
215
*/
223
216
private getRefsByObject (
224
- object : IOpenAPI3ObjectSchema ,
217
+ schema : IOpenAPI3ObjectSchema | IOpenAPI3EnumSchema | OpenAPI3Schema ,
225
218
objectRef : IOpenAPI3Reference ,
226
219
outerRefs : IOpenAPI3Reference [ ] = [ ]
227
220
) : IOpenAPI3Reference [ ] {
228
221
const refs = outerRefs ;
229
222
230
- Object . values ( object . properties || [ ] ) . forEach ( ( property ) => {
231
- this . getRefsFromSchema ( property )
232
- . filter ( ( ref ) => ref . $ref !== objectRef . $ref && ! outerRefs . find ( ( x ) => x . $ref === ref . $ref ) )
233
- . forEach ( ( ref ) => {
234
- refs . push ( ref ) ;
235
-
236
- if ( this . typesGuard . isObject ( property ) ) {
237
- this . getRefsByObject ( property , objectRef , refs ) ;
238
- }
239
- } ) ;
240
- } ) ;
223
+ const properties : OpenAPI3Schema [ ] = [ ] ;
241
224
242
- return refs ;
243
- }
225
+ if ( this . typesGuard . isAllOf ( schema ) ) {
226
+ properties . push ( ...schema . allOf ) ;
227
+ }
244
228
245
- /**
246
- * @description Gets refs from allof schema only one level down
247
- */
248
- private getRefsByAllOf (
249
- object : IOpenAPI3AllOfSchema ,
250
- objectRef : IOpenAPI3Reference ,
251
- outerRefs : IOpenAPI3Reference [ ] = [ ]
252
- ) : IOpenAPI3Reference [ ] {
253
- const refs = outerRefs ;
229
+ if ( this . typesGuard . isObject ( schema ) ) {
230
+ properties . push ( ...Object . values ( schema . properties || [ ] ) ) ;
231
+ }
254
232
255
- Object . values ( object . allOf || [ ] ) . forEach ( ( property ) => {
233
+ properties . forEach ( ( property ) => {
256
234
this . getRefsFromSchema ( property )
257
235
. filter ( ( ref ) => ref . $ref !== objectRef . $ref && ! outerRefs . find ( ( x ) => x . $ref === ref . $ref ) )
258
236
. forEach ( ( ref ) => {
259
237
refs . push ( ref ) ;
260
-
261
- if ( this . typesGuard . isObject ( property ) ) {
262
- this . getRefsByObject ( property , objectRef , refs ) ;
263
- }
238
+ this . getRefsByObject ( property , objectRef , refs ) ;
239
+ this . getRefsByObject ( property , objectRef , refs ) ;
264
240
} ) ;
265
241
} ) ;
266
242
0 commit comments