@@ -20,12 +20,12 @@ const methodAliases = {
2020 delete : ( pathName , hasPathInserts ) => _ . camelCase ( `${ pathName } _delete` ) ,
2121} ;
2222
23- const getSchemaFromRequestType = requestType => {
23+ const getSchemaFromRequestType = ( requestType ) => {
2424 const content = _ . get ( requestType , "content" ) ;
2525
2626 if ( ! content ) return null ;
2727
28- const contentByType = _ . find ( content , contentByType => contentByType . schema ) ;
28+ const contentByType = _ . find ( content , ( contentByType ) => contentByType . schema ) ;
2929
3030 return contentByType && contentByType . schema ;
3131} ;
@@ -40,15 +40,15 @@ const getTypeFromRequestInfo = (requestInfo, parsedSchemas, operationId, content
4040 const { content } = parseSchema ( schema , "none" , inlineExtraFormatters ) ;
4141 const foundedSchemaByName = _ . find (
4242 parsedSchemas ,
43- parsedSchema => parsedSchema . name === content ,
43+ ( parsedSchema ) => parsedSchema . name === content ,
4444 ) ;
45- const foundSchemaByContent = _ . find ( parsedSchemas , parsedSchema =>
45+ const foundSchemaByContent = _ . find ( parsedSchemas , ( parsedSchema ) =>
4646 _ . isEqual ( parsedSchema . content , content ) ,
4747 ) ;
4848
4949 const foundSchema = foundedSchemaByName || foundSchemaByContent ;
5050
51- return checkAndRenameModelName ( foundSchema ? foundSchema . name : content ) ;
51+ return foundSchema ? checkAndRenameModelName ( foundSchema . name ) : content ;
5252 }
5353
5454 if ( refTypeInfo ) {
@@ -57,7 +57,7 @@ const getTypeFromRequestInfo = (requestInfo, parsedSchemas, operationId, content
5757
5858 // TODO:HACK fix problem of swagger2opeanpi
5959 const typeNameWithoutOpId = _ . replace ( refTypeInfo . typeName , operationId , "" ) ;
60- if ( _ . find ( parsedSchemas , schema => schema . name === typeNameWithoutOpId ) )
60+ if ( _ . find ( parsedSchemas , ( schema ) => schema . name === typeNameWithoutOpId ) )
6161 return checkAndRenameModelName ( typeNameWithoutOpId ) ;
6262
6363 switch ( refTypeInfo . componentName ) {
@@ -95,14 +95,14 @@ const getTypesFromResponses = (responses, parsedSchemas, operationId) =>
9595 [ ] ,
9696 ) ;
9797
98- const isSuccessResponseStatus = status =>
98+ const isSuccessResponseStatus = ( status ) =>
9999 ( config . defaultResponseAsSuccess && status === "default" ) ||
100100 ( + status >= SUCCESS_RESPONSE_STATUS_RANGE [ 0 ] && + status < SUCCESS_RESPONSE_STATUS_RANGE [ 1 ] ) ;
101101
102- const findBadResponses = responses =>
102+ const findBadResponses = ( responses ) =>
103103 _ . filter ( responses , ( v , status ) => ! isSuccessResponseStatus ( status ) ) ;
104104
105- const findSuccessResponse = responses =>
105+ const findSuccessResponse = ( responses ) =>
106106 _ . find ( responses , ( v , status ) => isSuccessResponseStatus ( status ) ) ;
107107
108108const getReturnType = ( responses , parsedSchemas , operationId ) =>
@@ -112,8 +112,8 @@ const getReturnType = (responses, parsedSchemas, operationId) =>
112112const getErrorReturnType = ( responses , parsedSchemas , operationId ) =>
113113 _ . uniq (
114114 findBadResponses ( responses )
115- . map ( response => getTypeFromRequestInfo ( response , parsedSchemas , operationId ) )
116- . filter ( type => type !== DEFAULT_PRIMITIVE_TYPE ) ,
115+ . map ( ( response ) => getTypeFromRequestInfo ( response , parsedSchemas , operationId ) )
116+ . filter ( ( type ) => type !== DEFAULT_PRIMITIVE_TYPE ) ,
117117 ) . join ( " | " ) || DEFAULT_PRIMITIVE_TYPE ;
118118
119119const createCustomOperationId = ( method , route , moduleName ) => {
@@ -168,13 +168,13 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
168168 responses,
169169 } = requestInfo ;
170170 const hasSecurity = ! ! ( security && security . length ) ;
171- const pathParams = collect ( parameters , parameter => {
171+ const pathParams = collect ( parameters , ( parameter ) => {
172172 if ( parameter . in === "path" ) return parameter ;
173173
174174 const refTypeInfo = getRefType ( parameter ) ;
175175 return refTypeInfo && refTypeInfo . rawTypeData . in === "path" && refTypeInfo . rawTypeData ;
176176 } ) ;
177- const queryParams = collect ( parameters , parameter => {
177+ const queryParams = collect ( parameters , ( parameter ) => {
178178 if ( parameter . in === "query" ) return parameter ;
179179
180180 const refTypeInfo = getRefType ( parameter ) ;
@@ -216,16 +216,40 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
216216 ? getTypeFromRequestInfo ( requestBody , parsedSchemas , operationId )
217217 : null ;
218218
219- const pathArgs = _ . map ( pathParams , param => ( {
220- name : param . name ,
221- optional : ! param . required ,
222- type : parseSchema ( param . schema , null , inlineExtraFormatters ) . content ,
223- } ) ) ;
219+ // Gets all in path parameters from route
220+ // Example: someurl.com/{id}/{name}
221+ // returns: ["id", "name"]
222+ const insideRoutePathArgs = _ . compact (
223+ _ . split ( route , "{" ) . map ( ( part ) => ( part . includes ( "}" ) ? part . split ( "}" ) [ 0 ] : null ) ) ,
224+ ) ;
225+
226+ // Path args - someurl.com/{id}/{name}
227+ // id, name its path args
228+ const pathArgs = insideRoutePathArgs . length
229+ ? _ . map ( pathParams , ( param ) => ( {
230+ name : param . name ,
231+ optional : ! param . required ,
232+ type : parseSchema ( param . schema , null , inlineExtraFormatters ) . content ,
233+ } ) )
234+ : [ ] ;
235+
236+ insideRoutePathArgs . forEach ( ( routePathArg ) => {
237+ // Cases when in path parameters is not exist in "parameters"
238+ if ( ! pathArgs . find ( ( pathArg ) => pathArg && pathArg . name === routePathArg ) ) {
239+ pathArgs . push ( {
240+ name : routePathArg ,
241+ optional : false ,
242+ type : "string" ,
243+ } ) ;
244+ }
245+ } ) ;
224246
225247 const specificArgs = {
226248 query : queryType
227249 ? {
228- name : pathArgs . some ( pathArg => pathArg . name === "query" ) ? "queryParams" : "query" ,
250+ name : pathArgs . some ( ( pathArg ) => pathArg . name === "query" )
251+ ? "queryParams"
252+ : "query" ,
229253 optional : parseSchema ( queryObjectSchema , null ) . allFieldsAreOptional ,
230254 type : queryType ,
231255 }
@@ -239,15 +263,17 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
239263 }
240264 : void 0 ,
241265 requestParams : {
242- name : pathArgs . some ( pathArg => pathArg . name === "params" ) ? "requestParams" : "params" ,
266+ name : pathArgs . some ( ( pathArg ) => pathArg . name === "params" )
267+ ? "requestParams"
268+ : "params" ,
243269 optional : true ,
244270 type : "RequestParams" ,
245271 } ,
246272 } ;
247273
248274 let routeArgs = [ ...pathArgs , specificArgs . query , specificArgs . body ] . filter ( Boolean ) ;
249275
250- if ( routeArgs . some ( pathArg => pathArg . optional ) ) {
276+ if ( routeArgs . some ( ( pathArg ) => pathArg . optional ) ) {
251277 const { optionalArgs, requiredArgs } = _ . reduce (
252278 [ ...routeArgs ] ,
253279 ( acc , pathArg ) => {
@@ -326,7 +352,7 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
326352 ] ;
327353 } , [ ] ) ;
328354
329- const groupRoutes = routes => {
355+ const groupRoutes = ( routes ) => {
330356 const duplicates = { } ;
331357 return _ . reduce (
332358 routes . reduce (
0 commit comments