@@ -127,7 +127,7 @@ export default function generateTypesV3(input: OpenAPI3 | OpenAPI3Schemas, optio
127127 }
128128
129129 // 4. transform
130- output += transform ( value . schema ? value . schema : value ) ;
130+ output += transform ( value . schema || value ) ;
131131
132132 // 5. close nullable
133133 if ( value . nullable ) {
@@ -205,7 +205,15 @@ export default function generateTypesV3(input: OpenAPI3 | OpenAPI3Schemas, optio
205205 Object . entries ( operation . responses ) . forEach ( ( [ statusCodeString , response ] ) => {
206206 // NOTE: Numeric status codes and the "default" response.
207207 const statusCode = Number ( statusCodeString ) || statusCodeString ;
208- if ( ! response ) return ;
208+ if ( ! response || typeof response !== "object" ) return ;
209+
210+ // option 1: $ref
211+ if ( response . $ref ) {
212+ output += `${ statusCode } : ${ transformRef ( response . $ref ) } ;\n` ;
213+ return ;
214+ }
215+
216+ // option 2: inline schema
209217 if ( response . description ) output += comment ( response . description ) ;
210218 if ( ! response . content || ! Object . keys ( response . content ) . length ) {
211219 const type = statusCode === 204 || Math . floor ( + statusCode / 100 ) === 3 ? "never" : "unknown" ;
@@ -295,11 +303,22 @@ parameters: {
295303 ${ createKeys ( propertyMapped , Object . keys ( propertyMapped ) ) }
296304}` ;
297305 }
306+
307+ // add responses
298308 if ( components . responses && Object . keys ( components . responses ) . length ) {
299- finalOutput += `
300- responses: {
301- ${ createKeys ( components . responses , Object . keys ( components . responses ) ) }
302- }` ;
309+ finalOutput += "\nresponses: {\n" ; // open response
310+ for ( const [ contentType , responseComplete ] of Object . entries ( components . responses ) ) {
311+ const { description, ...response } = responseComplete ;
312+ if ( description ) finalOutput += comment ( description ) ;
313+ finalOutput += ` "${ contentType } ": {\n` ; // open content type
314+ Object . entries ( response ) . forEach ( ( [ property , value ] ) => {
315+ finalOutput += ` "${ property } ": {\n` ; // open property
316+ finalOutput += ` ${ createKeys ( value , Object . keys ( value ) ) } \n` ;
317+ finalOutput += ` }\n` ; // close property
318+ } ) ;
319+ finalOutput += " }\n" ; // close content type
320+ }
321+ finalOutput += "}\n" ; // close response
303322 }
304323
305324 // close components wrapper
0 commit comments