@@ -46,13 +46,19 @@ const getSchemaFromRequestType = (requestInfo) => {
46
46
return null ;
47
47
} ;
48
48
49
- const getTypeFromRequestInfo = ( { requestInfo, parsedSchemas, operationId, defaultType } ) => {
49
+ const getTypeFromRequestInfo = ( {
50
+ requestInfo,
51
+ parsedSchemas,
52
+ operationId,
53
+ defaultType,
54
+ typeName,
55
+ } ) => {
50
56
// TODO: make more flexible pick schema without content type
51
57
const schema = getSchemaFromRequestType ( requestInfo ) ;
52
58
const refTypeInfo = getRefType ( requestInfo ) ;
53
59
54
60
if ( schema ) {
55
- const content = getInlineParseContent ( schema , "none" ) ;
61
+ const content = getInlineParseContent ( schema , typeName ) ;
56
62
const foundedSchemaByName = _ . find (
57
63
parsedSchemas ,
58
64
( parsedSchema ) => formatModelName ( parsedSchema . name ) === content ,
@@ -81,9 +87,12 @@ const getTypeFromRequestInfo = ({ requestInfo, parsedSchemas, operationId, defau
81
87
return formatModelName ( refTypeInfo . typeName ) ;
82
88
case "responses" :
83
89
case "requestBodies" :
84
- return getInlineParseContent ( getSchemaFromRequestType ( refTypeInfo . rawTypeData ) , "none" ) ;
90
+ return getInlineParseContent (
91
+ getSchemaFromRequestType ( refTypeInfo . rawTypeData ) ,
92
+ refTypeInfo . typeName || null ,
93
+ ) ;
85
94
default :
86
- return getInlineParseContent ( refTypeInfo . rawTypeData , "none" ) ;
95
+ return getInlineParseContent ( refTypeInfo . rawTypeData , refTypeInfo . typeName || null ) ;
87
96
}
88
97
}
89
98
@@ -396,13 +405,23 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
396
405
) ;
397
406
let contentKind = getContentKind ( contentTypes ) ;
398
407
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
+
399
418
if ( routeParams . formData . length ) {
400
419
contentKind = CONTENT_KIND . FORM_DATA ;
401
420
schema = convertRouteParamsIntoObject ( routeParams . formData ) ;
402
- type = getInlineParseContent ( schema ) ;
421
+ type = getInlineParseContent ( schema , typeName ) ;
403
422
} else if ( contentKind === CONTENT_KIND . FORM_DATA ) {
404
423
schema = getSchemaFromRequestType ( requestBody ) ;
405
- type = getInlineParseContent ( schema ) ;
424
+ type = getInlineParseContent ( schema , typeName ) ;
406
425
} else if ( requestBody ) {
407
426
schema = getSchemaFromRequestType ( requestBody ) ;
408
427
type = checkAndAddNull (
@@ -411,6 +430,7 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
411
430
requestInfo : requestBody ,
412
431
parsedSchemas,
413
432
operationId,
433
+ typeName,
414
434
} ) ,
415
435
) ;
416
436
@@ -423,13 +443,8 @@ const getRequestBodyInfo = (routeInfo, routeParams, parsedSchemas, routeName) =>
423
443
}
424
444
425
445
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
- ] ) ;
431
446
schema = createComponent ( "schemas" , typeName , { ...schema } ) ;
432
- type = typeName ;
447
+ type = getInlineParseContent ( schema ) ;
433
448
}
434
449
435
450
return {
0 commit comments