@@ -46,13 +46,19 @@ const getSchemaFromRequestType = (requestInfo) => {
4646 return null ;
4747} ;
4848
49- const getTypeFromRequestInfo = ( { requestInfo, parsedSchemas, operationId, defaultType } ) => {
49+ const getTypeFromRequestInfo = ( {
50+ requestInfo,
51+ parsedSchemas,
52+ operationId,
53+ defaultType,
54+ typeName,
55+ } ) => {
5056 // TODO: make more flexible pick schema without content type
5157 const schema = getSchemaFromRequestType ( requestInfo ) ;
5258 const refTypeInfo = getRefType ( requestInfo ) ;
5359
5460 if ( schema ) {
55- const content = getInlineParseContent ( schema , "none" ) ;
61+ const content = getInlineParseContent ( schema , typeName ) ;
5662 const foundedSchemaByName = _ . find (
5763 parsedSchemas ,
5864 ( parsedSchema ) => formatModelName ( parsedSchema . name ) === content ,
@@ -81,9 +87,12 @@ const getTypeFromRequestInfo = ({ requestInfo, parsedSchemas, operationId, defau
8187 return formatModelName ( refTypeInfo . typeName ) ;
8288 case "responses" :
8389 case "requestBodies" :
84- return getInlineParseContent ( getSchemaFromRequestType ( refTypeInfo . rawTypeData ) , "none" ) ;
90+ return getInlineParseContent (
91+ getSchemaFromRequestType ( refTypeInfo . rawTypeData ) ,
92+ refTypeInfo . typeName || null ,
93+ ) ;
8594 default :
86- return getInlineParseContent ( refTypeInfo . rawTypeData , "none" ) ;
95+ return getInlineParseContent ( refTypeInfo . rawTypeData , refTypeInfo . typeName || null ) ;
8796 }
8897 }
8998
@@ -396,13 +405,23 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
396405 ) ;
397406 let contentKind = getContentKind ( contentTypes ) ;
398407
408+ let typeName = null ;
409+
410+ if ( config . extractRequestBody ) {
411+ typeName = config . componentTypeNameResolver . resolve ( [
412+ classNameCase ( `${ routeName . usage } Payload` ) ,
413+ classNameCase ( `${ routeName . usage } Body` ) ,
414+ classNameCase ( `${ routeName . usage } Input` ) ,
415+ ] ) ;
416+ }
417+
399418 if ( routeParams . formData . length ) {
400419 contentKind = CONTENT_KIND . FORM_DATA ;
401420 schema = convertRouteParamsIntoObject ( routeParams . formData ) ;
402- type = getInlineParseContent ( schema ) ;
421+ type = getInlineParseContent ( schema , typeName ) ;
403422 } else if ( contentKind === CONTENT_KIND . FORM_DATA ) {
404423 schema = getSchemaFromRequestType ( requestBody ) ;
405- type = getInlineParseContent ( schema ) ;
424+ type = getInlineParseContent ( schema , typeName ) ;
406425 } else if ( requestBody ) {
407426 schema = getSchemaFromRequestType ( requestBody ) ;
408427 type = checkAndAddNull (
@@ -411,6 +430,7 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
411430 requestInfo : requestBody ,
412431 parsedSchemas,
413432 operationId,
433+ typeName,
414434 } ) ,
415435 ) ;
416436
@@ -423,13 +443,8 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
423443 }
424444
425445 if ( schema && ! schema . $ref && config . extractRequestBody ) {
426- const typeName = config . componentTypeNameResolver . resolve ( [
427- classNameCase ( `${ routeName . usage } Payload` ) ,
428- classNameCase ( `${ routeName . usage } Body` ) ,
429- classNameCase ( `${ routeName . usage } Input` ) ,
430- ] ) ;
431446 schema = createComponent ( "schemas" , typeName , { ...schema } ) ;
432- type = typeName ;
447+ type = getInlineParseContent ( schema ) ;
433448 }
434449
435450 return {
0 commit comments