11import  camelcase  from  'camelcase' 
22import  {  ISwaggerOptions  }  from  '../baseInterfaces' 
3- import  {  IPaths  }  from  '../swaggerInterfaces' 
3+ import  {  IParameter ,   IPaths ,   IRequestUrl  }  from  '../swaggerInterfaces' 
44import  {  getClassNameByPath ,  getMethodNameByPath ,  RemoveSpecialCharacters  }  from  '../utils' 
55import  {  getContentType  }  from  './getContentType' 
66import  {  getRequestBody  }  from  './getRequestBody' 
@@ -22,7 +22,14 @@ export function requestCodegen(paths: IPaths, isV3: boolean, options: ISwaggerOp
2222  const  requestClasses : IRequestClass  =  { } 
2323
2424  if  ( ! ! paths ) 
25-     for  ( const  [ path ,  request ]  of  Object . entries ( paths ) )  { 
25+     for  ( const  [ path ,  requestAndParams ]  of  Object . entries ( paths ) )  { 
26+       // are there parameters that are needed for all methods of this path? 
27+       const  pathLevelParams  =  requestAndParams . parameters 
28+       // if there were path level parameters present, we delete them 
29+       // so we do not accidentally interpret them as a http method later 
30+       if  ( pathLevelParams )  delete  requestAndParams [ 'parameters' ] 
31+       const  request  =  requestAndParams  as  IRequestUrl 
32+       
2633      let  methodName  =  getMethodNameByPath ( path ) 
2734      for  ( const  [ method ,  reqProps ]  of  Object . entries ( request ) )  { 
2835        methodName  = 
@@ -73,9 +80,15 @@ export function requestCodegen(paths: IPaths, isV3: boolean, options: ISwaggerOp
7380
7481        const  multipartDataProperties  =  reqProps ?. requestBody ?. content [ 'multipart/form-data' ] 
7582
76-         if  ( reqProps . parameters  ||  multipartDataProperties )  { 
83+         if  ( pathLevelParams   ||   reqProps . parameters  ||  multipartDataProperties )  { 
7784          // 获取到接口的参数 
78-           let  tempParameters  =  reqProps . parameters  ||  [ ] 
85+           let  tempParameters : IParameter [ ]  =  [ ] 
86+           if  ( reqProps . parameters )  { 
87+             tempParameters  =  tempParameters . concat ( reqProps . parameters ) 
88+           } 
89+           if  ( pathLevelParams )  { 
90+             tempParameters  =  tempParameters . concat ( pathLevelParams ) 
91+           } 
7992
8093          // 合并两个参数类型 
8194          if  ( multipartDataProperties )  { 
0 commit comments