@@ -20,12 +20,12 @@ const methodAliases = {
20
20
delete : ( pathName , hasPathInserts ) => _ . camelCase ( `${ pathName } _delete` ) ,
21
21
} ;
22
22
23
- const getSchemaFromRequestType = requestType => {
23
+ const getSchemaFromRequestType = ( requestType ) => {
24
24
const content = _ . get ( requestType , "content" ) ;
25
25
26
26
if ( ! content ) return null ;
27
27
28
- const contentByType = _ . find ( content , contentByType => contentByType . schema ) ;
28
+ const contentByType = _ . find ( content , ( contentByType ) => contentByType . schema ) ;
29
29
30
30
return contentByType && contentByType . schema ;
31
31
} ;
@@ -40,15 +40,15 @@ const getTypeFromRequestInfo = (requestInfo, parsedSchemas, operationId, content
40
40
const { content } = parseSchema ( schema , "none" , inlineExtraFormatters ) ;
41
41
const foundedSchemaByName = _ . find (
42
42
parsedSchemas ,
43
- parsedSchema => parsedSchema . name === content ,
43
+ ( parsedSchema ) => parsedSchema . name === content ,
44
44
) ;
45
- const foundSchemaByContent = _ . find ( parsedSchemas , parsedSchema =>
45
+ const foundSchemaByContent = _ . find ( parsedSchemas , ( parsedSchema ) =>
46
46
_ . isEqual ( parsedSchema . content , content ) ,
47
47
) ;
48
48
49
49
const foundSchema = foundedSchemaByName || foundSchemaByContent ;
50
50
51
- return checkAndRenameModelName ( foundSchema ? foundSchema . name : content ) ;
51
+ return foundSchema ? checkAndRenameModelName ( foundSchema . name ) : content ;
52
52
}
53
53
54
54
if ( refTypeInfo ) {
@@ -57,7 +57,7 @@ const getTypeFromRequestInfo = (requestInfo, parsedSchemas, operationId, content
57
57
58
58
// TODO:HACK fix problem of swagger2opeanpi
59
59
const typeNameWithoutOpId = _ . replace ( refTypeInfo . typeName , operationId , "" ) ;
60
- if ( _ . find ( parsedSchemas , schema => schema . name === typeNameWithoutOpId ) )
60
+ if ( _ . find ( parsedSchemas , ( schema ) => schema . name === typeNameWithoutOpId ) )
61
61
return checkAndRenameModelName ( typeNameWithoutOpId ) ;
62
62
63
63
switch ( refTypeInfo . componentName ) {
@@ -95,14 +95,14 @@ const getTypesFromResponses = (responses, parsedSchemas, operationId) =>
95
95
[ ] ,
96
96
) ;
97
97
98
- const isSuccessResponseStatus = status =>
98
+ const isSuccessResponseStatus = ( status ) =>
99
99
( config . defaultResponseAsSuccess && status === "default" ) ||
100
100
( + status >= SUCCESS_RESPONSE_STATUS_RANGE [ 0 ] && + status < SUCCESS_RESPONSE_STATUS_RANGE [ 1 ] ) ;
101
101
102
- const findBadResponses = responses =>
102
+ const findBadResponses = ( responses ) =>
103
103
_ . filter ( responses , ( v , status ) => ! isSuccessResponseStatus ( status ) ) ;
104
104
105
- const findSuccessResponse = responses =>
105
+ const findSuccessResponse = ( responses ) =>
106
106
_ . find ( responses , ( v , status ) => isSuccessResponseStatus ( status ) ) ;
107
107
108
108
const getReturnType = ( responses , parsedSchemas , operationId ) =>
@@ -112,8 +112,8 @@ const getReturnType = (responses, parsedSchemas, operationId) =>
112
112
const getErrorReturnType = ( responses , parsedSchemas , operationId ) =>
113
113
_ . uniq (
114
114
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 ) ,
117
117
) . join ( " | " ) || DEFAULT_PRIMITIVE_TYPE ;
118
118
119
119
const createCustomOperationId = ( method , route , moduleName ) => {
@@ -168,13 +168,13 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
168
168
responses,
169
169
} = requestInfo ;
170
170
const hasSecurity = ! ! ( security && security . length ) ;
171
- const pathParams = collect ( parameters , parameter => {
171
+ const pathParams = collect ( parameters , ( parameter ) => {
172
172
if ( parameter . in === "path" ) return parameter ;
173
173
174
174
const refTypeInfo = getRefType ( parameter ) ;
175
175
return refTypeInfo && refTypeInfo . rawTypeData . in === "path" && refTypeInfo . rawTypeData ;
176
176
} ) ;
177
- const queryParams = collect ( parameters , parameter => {
177
+ const queryParams = collect ( parameters , ( parameter ) => {
178
178
if ( parameter . in === "query" ) return parameter ;
179
179
180
180
const refTypeInfo = getRefType ( parameter ) ;
@@ -216,16 +216,40 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
216
216
? getTypeFromRequestInfo ( requestBody , parsedSchemas , operationId )
217
217
: null ;
218
218
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
+ } ) ;
224
246
225
247
const specificArgs = {
226
248
query : queryType
227
249
? {
228
- name : pathArgs . some ( pathArg => pathArg . name === "query" ) ? "queryParams" : "query" ,
250
+ name : pathArgs . some ( ( pathArg ) => pathArg . name === "query" )
251
+ ? "queryParams"
252
+ : "query" ,
229
253
optional : parseSchema ( queryObjectSchema , null ) . allFieldsAreOptional ,
230
254
type : queryType ,
231
255
}
@@ -239,15 +263,17 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
239
263
}
240
264
: void 0 ,
241
265
requestParams : {
242
- name : pathArgs . some ( pathArg => pathArg . name === "params" ) ? "requestParams" : "params" ,
266
+ name : pathArgs . some ( ( pathArg ) => pathArg . name === "params" )
267
+ ? "requestParams"
268
+ : "params" ,
243
269
optional : true ,
244
270
type : "RequestParams" ,
245
271
} ,
246
272
} ;
247
273
248
274
let routeArgs = [ ...pathArgs , specificArgs . query , specificArgs . body ] . filter ( Boolean ) ;
249
275
250
- if ( routeArgs . some ( pathArg => pathArg . optional ) ) {
276
+ if ( routeArgs . some ( ( pathArg ) => pathArg . optional ) ) {
251
277
const { optionalArgs, requiredArgs } = _ . reduce (
252
278
[ ...routeArgs ] ,
253
279
( acc , pathArg ) => {
@@ -326,7 +352,7 @@ const parseRoutes = ({ paths }, parsedSchemas) =>
326
352
] ;
327
353
} , [ ] ) ;
328
354
329
- const groupRoutes = routes => {
355
+ const groupRoutes = ( routes ) => {
330
356
const duplicates = { } ;
331
357
return _ . reduce (
332
358
routes . reduce (
0 commit comments