@@ -32,7 +32,7 @@ export function getFullPath(route: IRoute): string {
3232 */
3333export function getOperation (
3434 route : IRoute ,
35- schemas : { [ p : string ] : oa . SchemaObject }
35+ schemas : { [ p : string ] : oa . SchemaObject | oa . ReferenceObject }
3636) : oa . OperationObject {
3737 const operation : oa . OperationObject = {
3838 operationId : getOperationId ( route ) ,
@@ -52,7 +52,7 @@ export function getOperation(
5252 ( [ _ , value ] ) => value && ( value . length || Object . keys ( value ) . length )
5353 )
5454 . reduce ( ( acc , [ key , value ] ) => {
55- acc [ key ] = value
55+ acc [ key as keyof oa . OperationObject ] = value
5656 return acc
5757 } , { } as unknown as oa . OperationObject )
5858
@@ -71,7 +71,7 @@ export function getOperationId(route: IRoute): string {
7171 */
7272export function getPaths (
7373 routes : IRoute [ ] ,
74- schemas : { [ p : string ] : oa . SchemaObject }
74+ schemas : { [ p : string ] : oa . SchemaObject | oa . ReferenceObject }
7575) : oa . PathObject {
7676 const routePaths = routes . map ( ( route ) => ( {
7777 [ getFullPath ( route ) ] : {
@@ -156,7 +156,7 @@ export function getPathParams(route: IRoute): oa.ParameterObject[] {
156156 */
157157export function getQueryParams (
158158 route : IRoute ,
159- schemas : { [ p : string ] : oa . SchemaObject }
159+ schemas : { [ p : string ] : oa . SchemaObject | oa . ReferenceObject }
160160) : oa . ParameterObject [ ] {
161161 const queries : oa . ParameterObject [ ] = route . params
162162 . filter ( ( p ) => p . type === 'query' )
@@ -177,15 +177,17 @@ export function getQueryParams(
177177 const paramSchemaName = paramSchema . $ref . split ( '/' ) . pop ( ) || ''
178178 const currentSchema = schemas [ paramSchemaName ]
179179
180- for ( const [ name , schema ] of Object . entries (
181- currentSchema ?. properties || { }
182- ) ) {
183- queries . push ( {
184- in : 'query' ,
185- name,
186- required : currentSchema . required ?. includes ( name ) ,
187- schema,
188- } )
180+ if ( oa . isSchemaObject ( currentSchema ) ) {
181+ for ( const [ name , schema ] of Object . entries (
182+ currentSchema ?. properties || { }
183+ ) ) {
184+ queries . push ( {
185+ in : 'query' ,
186+ name,
187+ required : currentSchema . required ?. includes ( name ) ,
188+ schema,
189+ } )
190+ }
189191 }
190192 }
191193 return queries
@@ -243,8 +245,9 @@ export function getRequestBody(route: IRoute): oa.RequestBodyObject | void {
243245 const bodyMeta = route . params . find ( ( d ) => d . type === 'body' )
244246 if ( bodyMeta ) {
245247 const bodySchema = getParamSchema ( bodyMeta )
246- const { $ref } =
248+ const items =
247249 'items' in bodySchema && bodySchema . items ? bodySchema . items : bodySchema
250+ const $ref = oa . isReferenceObject ( items ) ? items . $ref : ''
248251
249252 return {
250253 content : {
@@ -308,7 +311,7 @@ export function getResponses(route: IRoute): oa.ResponsesObject {
308311 */
309312export function getSpec (
310313 routes : IRoute [ ] ,
311- schemas : { [ p : string ] : oa . SchemaObject }
314+ schemas : { [ p : string ] : oa . SchemaObject | oa . ReferenceObject }
312315) : oa . OpenAPIObject {
313316 return {
314317 components : { schemas : { } } ,
0 commit comments