Skip to content

Commit e2750ff

Browse files
committed
fix: bug with kebab-case path params (issue #184, thanks @Mr-sgreen)
1 parent 1cea367 commit e2750ff

File tree

18 files changed

+1009
-916
lines changed

18 files changed

+1009
-916
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# next release
22

3+
4+
Fixes:
5+
- Bug with `kebab-case` path params (issue #184, thanks @Mr-sgreen)
6+
37
# 6.0.0
48

59
BREAKING_CHANGES:

src/routes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const parseRoute = (route) => {
139139
...pathParams,
140140
{
141141
$match: match,
142-
name: paramName,
142+
name: _.camelCase(paramName),
143143
required: true,
144144
type: "string",
145145
description: "",
@@ -162,6 +162,7 @@ const parseRoute = (route) => {
162162
);
163163

164164
return {
165+
originalRoute: route || "",
165166
route: fixedRoute,
166167
pathParams,
167168
};
@@ -206,6 +207,10 @@ const getRouteParams = (routeInfo, pathParams) => {
206207
};
207208
}
208209

210+
if (routeParam.in === "path" && routeParam.name) {
211+
routeParam.name = _.camelCase(routeParam.name);
212+
}
213+
209214
if (routeParam) {
210215
routeParams[routeParam.in].push(routeParam);
211216
}

tests/generated/v2.0/adafruit.ts

Lines changed: 87 additions & 87 deletions
Large diffs are not rendered by default.

tests/generated/v2.0/authentiq.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
269269
*/
270270
wrongPathParams1: (
271271
pathParam1: string,
272-
path_param2: string,
273-
path_param3: string,
272+
pathParam2: string,
273+
pathParam3: string,
274274
pathParam4: string,
275275
params: RequestParams = {},
276276
) =>
277277
this.request<void, any>({
278-
path: `/wrong-path-params1/${pathParam1}/${path_param2}/${path_param3}/${pathParam4}`,
278+
path: `/wrong-path-params1/${pathParam1}/${pathParam2}/${pathParam3}/${pathParam4}`,
279279
method: "DELETE",
280280
...params,
281281
}),
@@ -288,7 +288,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
288288
* @name WrongPathParams2
289289
* @request DELETE:/wrong-path-params2
290290
*/
291-
wrongPathParams2: (path_param1: string, params: RequestParams = {}) =>
291+
wrongPathParams2: (pathParam1: string, params: RequestParams = {}) =>
292292
this.request<void, any>({
293293
path: `/wrong-path-params2`,
294294
method: "DELETE",
@@ -335,9 +335,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
335335
* @name KeyRevoke
336336
* @request DELETE:/key/{PK}
337337
*/
338-
keyRevoke: (PK: string, query: { secret: string }, params: RequestParams = {}) =>
338+
keyRevoke: (pk: string, query: { secret: string }, params: RequestParams = {}) =>
339339
this.request<{ status?: string }, Error>({
340-
path: `/key/${PK}`,
340+
path: `/key/${pk}`,
341341
method: "DELETE",
342342
query: query,
343343
format: "json",
@@ -351,9 +351,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
351351
* @name GetKey
352352
* @request GET:/key/{PK}
353353
*/
354-
getKey: (PK: string, params: RequestParams = {}) =>
354+
getKey: (pk: string, params: RequestParams = {}) =>
355355
this.request<{ since?: string; status?: string; sub?: string }, Error>({
356-
path: `/key/${PK}`,
356+
path: `/key/${pk}`,
357357
method: "GET",
358358
format: "json",
359359
...params,
@@ -366,9 +366,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
366366
* @name HeadKey
367367
* @request HEAD:/key/{PK}
368368
*/
369-
headKey: (PK: string, params: RequestParams = {}) =>
369+
headKey: (pk: string, params: RequestParams = {}) =>
370370
this.request<void, Error>({
371-
path: `/key/${PK}`,
371+
path: `/key/${pk}`,
372372
method: "HEAD",
373373
...params,
374374
}),
@@ -380,9 +380,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
380380
* @name KeyUpdate
381381
* @request POST:/key/{PK}
382382
*/
383-
keyUpdate: (PK: string, body: AuthentiqID, params: RequestParams = {}) =>
383+
keyUpdate: (pk: string, body: AuthentiqID, params: RequestParams = {}) =>
384384
this.request<{ status?: string }, Error>({
385-
path: `/key/${PK}`,
385+
path: `/key/${pk}`,
386386
method: "POST",
387387
body: body,
388388
format: "json",
@@ -396,9 +396,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
396396
* @name KeyBind
397397
* @request PUT:/key/{PK}
398398
*/
399-
keyBind: (PK: string, body: AuthentiqID, params: RequestParams = {}) =>
399+
keyBind: (pk: string, body: AuthentiqID, params: RequestParams = {}) =>
400400
this.request<{ status?: string }, Error>({
401-
path: `/key/${PK}`,
401+
path: `/key/${pk}`,
402402
method: "PUT",
403403
body: body,
404404
format: "json",

tests/generated/v2.0/furkot-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
296296
* @request GET:/trip/{trip_id}/stop
297297
* @secure
298298
*/
299-
stopDetail: (trip_id: string, params: RequestParams = {}) =>
299+
stopDetail: (tripId: string, params: RequestParams = {}) =>
300300
this.request<Step[], any>({
301-
path: `/trip/${trip_id}/stop`,
301+
path: `/trip/${tripId}/stop`,
302302
method: "GET",
303303
secure: true,
304304
format: "json",

tests/generated/v2.0/github-swagger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,12 +4527,12 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
45274527
reposDetail2: (
45284528
owner: string,
45294529
repo: string,
4530-
archive_format: "tarball" | "zipball",
4530+
archiveFormat: "tarball" | "zipball",
45314531
path: string,
45324532
params: RequestParams = {},
45334533
) =>
45344534
this.request<any, void>({
4535-
path: `/repos/${owner}/${repo}/${archive_format}/${path}`,
4535+
path: `/repos/${owner}/${repo}/${archiveFormat}/${path}`,
45364536
method: "GET",
45374537
...params,
45384538
}),

tests/generated/v2.0/petstore-expanded.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ export class HttpClient<SecurityDataType = unknown> {
244244
* A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
245245
*/
246246
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
247+
pathParams = {
248+
/**
249+
* No description
250+
*
251+
* @name PathParamFooBarBazList
252+
* @request GET:/path-params/{path-param}/{foo-bar-baz}
253+
*/
254+
pathParamFooBarBazList: (pathParam: string, fooBarBaz: string, params: RequestParams = {}) =>
255+
this.request<any, void>({
256+
path: `/path-params/${pathParam}/${fooBarBaz}`,
257+
method: "GET",
258+
...params,
259+
}),
260+
};
247261
pets = {
248262
/**
249263
* @description Returns all pets from the system that the user has access to Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.

0 commit comments

Comments
 (0)