@@ -132,10 +132,10 @@ function migGeneralParameter(parameter: OpenAPIV2.GeneralParameterObject | OpenA
132132 }
133133
134134 const { $ref, in : in_ , name, required, description, ...schema } = parameter ;
135- const inQuery = in_ === 'query' ;
135+ const inV3 = in_ === 'cookie' || in_ === 'header' || in_ === 'path' ? in_ : 'query' ;
136+ const inQuery = inV3 === 'query' ;
136137 const style = inQuery ? collectionFormatMap [ parameter . collectionFormat || 'csv' ] : undefined ;
137138 const explode = inQuery ? explodeMap [ parameter . collectionFormat || 'csv' ] : undefined ;
138- const inV3 = in_ === 'cookie' || in_ === 'header' || in_ === 'path' ? in_ : 'query' ;
139139
140140 return {
141141 in : inV3 ,
@@ -150,15 +150,8 @@ function migGeneralParameter(parameter: OpenAPIV2.GeneralParameterObject | OpenA
150150
151151function makeRequestBody ( bodySchema : BodySchema [ ] , medias : string [ ] ) : OpenAPIV3 . RequestBodyObject {
152152 let requestBodySchema : OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject | undefined ;
153- const bodyRequest = bodySchema . find ( ( { parameter } ) => parameter . in === 'body' ) ;
154- const requestBodyRest = { } ;
155153
156- if ( bodyRequest ) {
157- requestBodySchema = bodyRequest . schema ;
158- const { required, description } = bodyRequest . parameter ;
159- Object . assign ( requestBodyRest , { required, description } ) ;
160- }
161- else if ( bodySchema . length > 0 ) {
154+ if ( bodySchema . length > 0 ) {
162155 requestBodySchema = {
163156 type : 'object' ,
164157 properties : bodySchema . reduce (
@@ -178,7 +171,6 @@ function makeRequestBody(bodySchema: BodySchema[], medias: string[]): OpenAPIV3.
178171 }
179172
180173 return {
181- ...requestBodyRest ,
182174 content : requestBodySchema
183175 ? medias . reduce (
184176 ( content , media ) => {
@@ -196,13 +188,13 @@ interface BodySchema {
196188 parameter : OpenAPIV2 . Parameter ;
197189 schema : OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject ;
198190}
199- function migOperation ( operation : OpenAPIV2 . OperationObject ) : OpenAPIV3 . OperationObject {
191+ function migOperation ( operation : OpenAPIV2 . OperationObject , migBody = false ) : OpenAPIV3 . OperationObject {
200192 const { parameters, responses, consumes, produces, ...rest } = operation ;
201193 const generalParameters : ( OpenAPIV3 . ParameterObject | OpenAPIV3 . ReferenceObject ) [ ] = [ ] ;
202194 const inBodySchemas : BodySchema [ ] = [ ] ;
203195
204196 parameters ?. forEach ( ( parameter ) => {
205- if ( 'in' in parameter && bodyIns . includes ( parameter . in ) ) {
197+ if ( migBody && 'in' in parameter && bodyIns . includes ( parameter . in ) ) {
206198 const schema = extractParameterSchema ( parameter ) ;
207199 inBodySchemas . push ( {
208200 parameter,
@@ -233,12 +225,12 @@ function migPathItem(pathItem: OpenAPIV2.PathItemObject | undefined): OpenAPIV3.
233225 // 忽略
234226 // parameters: parameters && parameters.map(migParameter),
235227 get : get && migOperation ( get ) ,
236- delete : delete_ && migOperation ( delete_ ) ,
228+ delete : delete_ && migOperation ( delete_ , true ) ,
237229 head : head && migOperation ( head ) ,
238230 options : options && migOperation ( options ) ,
239- patch : patch && migOperation ( patch ) ,
240- post : post && migOperation ( post ) ,
241- put : put && migOperation ( put ) ,
231+ patch : patch && migOperation ( patch , true ) ,
232+ post : post && migOperation ( post , true ) ,
233+ put : put && migOperation ( put , true ) ,
242234 } ;
243235}
244236
0 commit comments