@@ -155,7 +155,23 @@ export class SchemaResolver {
155155 }
156156
157157 private initializeSchemaTags ( ) {
158- const filterRefObjs = ( objs ?: unknown [ ] ) => objs ?. filter ( isReferenceObject ) ?? [ ] ;
158+ const getSchemaRefs = (
159+ schema : OpenAPIV3 . ReferenceObject | OpenAPIV3 . SchemaObject | undefined ,
160+ ) : OpenAPIV3 . ReferenceObject [ ] => {
161+ const schemaRefObjs : OpenAPIV3 . ReferenceObject [ ] = [ ] ;
162+ if ( ! schema ) {
163+ return schemaRefObjs ;
164+ }
165+
166+ if ( isReferenceObject ( schema ) ) {
167+ schemaRefObjs . push ( schema ) ;
168+ } else if ( schema . allOf || schema . anyOf || schema . oneOf ) {
169+ const schemaObjs = schema . allOf ?? schema . anyOf ?? schema . oneOf ?? [ ] ;
170+ schemaObjs . forEach ( ( schema ) => schemaRefObjs . push ( ...getSchemaRefs ( schema ) ) ) ;
171+ }
172+
173+ return schemaRefObjs ;
174+ } ;
159175
160176 for ( const path in this . openApiDoc . paths ) {
161177 const pathItemObj = this . openApiDoc . paths [ path ] as OpenAPIV3 . PathItemObject ;
@@ -170,20 +186,17 @@ export class SchemaResolver {
170186
171187 // Collect all parameter objects that are references
172188 const schemaRefObjs = [ ] as OpenAPIV3 . ReferenceObject [ ] ;
173- schemaRefObjs . push (
174- ... filterRefObjs ( operation . parameters ?. map ( ( param ) => ( param as OpenAPIV3 . ParameterObject ) . schema ) ) ,
175- ) ;
189+ operation . parameters ?. map ( ( param ) => {
190+ schemaRefObjs . push ( ... getSchemaRefs ( ( param as OpenAPIV3 . ParameterObject ) . schema ) ) ;
191+ } ) ;
176192
177193 // Collect all requestBody objects that are references
178194 if ( operation . requestBody ) {
179195 const requestBodyObj = this . resolveObject ( operation . requestBody ) ;
180196 const mediaTypes = Object . keys ( requestBodyObj . content ?? { } ) ;
181197 const matchingMediaType = mediaTypes . find ( isParamMediaTypeAllowed ) ;
182198 if ( matchingMediaType ) {
183- const schema = requestBodyObj . content ?. [ matchingMediaType ] ?. schema ;
184- if ( isReferenceObject ( schema ) ) {
185- schemaRefObjs . push ( schema ) ;
186- }
199+ schemaRefObjs . push ( ...getSchemaRefs ( requestBodyObj . content ?. [ matchingMediaType ] ?. schema ) ) ;
187200 }
188201 }
189202
@@ -193,10 +206,7 @@ export class SchemaResolver {
193206 const mediaTypes = Object . keys ( responseObj . content ?? { } ) ;
194207 const matchingMediaType = mediaTypes . find ( isMediaTypeAllowed ) ;
195208 if ( matchingMediaType ) {
196- const schema = responseObj . content ?. [ matchingMediaType ] ?. schema ;
197- if ( isReferenceObject ( schema ) ) {
198- schemaRefObjs . push ( schema ) ;
199- }
209+ schemaRefObjs . push ( ...getSchemaRefs ( responseObj . content ?. [ matchingMediaType ] ?. schema ) ) ;
200210 }
201211 }
202212
0 commit comments