Skip to content

Commit caccd4b

Browse files
authored
Merge pull request #1064 from nicky1038/bugfix/fix-route-path-params-parsing
Fix route param parsing when the param begins with just one letter (rebased original PR #686 by @ahoseinian)
2 parents 14078b5 + 6d9e920 commit caccd4b

File tree

4 files changed

+146
-1
lines changed

4 files changed

+146
-1
lines changed

.changeset/honest-bears-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"swagger-typescript-api": patch
3+
---
4+
5+
Fix query params detection on route name parsing

src/schema-routes/schema-routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ export class SchemaRoutes {
9595
this.config.hooks.onPreBuildRoutePath(originalRouteName) ||
9696
originalRouteName;
9797

98+
// TODO forbid leading symbols [\]^` in a major release (allowed yet for backwards compatibility)
9899
const pathParamMatches = (routeName || "").match(
99-
/({(([A-z]){1}([a-zA-Z0-9]-?_?\.?)+)([0-9]+)?})|(:(([A-z]){1}([a-zA-Z0-9]-?_?\.?)+)([0-9]+)?:?)/g,
100+
/({[\w[\\\]^`][-_.\w]*})|(:[\w[\\\]^`][-_.\w]*:?)/g,
100101
);
101102

102103
// used in case when path parameters is not declared in requestInfo.parameters ("in": "path")

tests/spec/extractRequestParams/__snapshots__/basic.test.ts.snap

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,52 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
476476
...params,
477477
}),
478478
};
479+
iKey = {
480+
/**
481+
* @description Get public details of an Authentiq ID.
482+
*
483+
* @tags key, get
484+
* @name IKeyDetail
485+
* @request GET:/i_key/{i_PK}
486+
*/
487+
iKeyDetail: (iPk: string, params: RequestParams = {}) =>
488+
this.request<
489+
{
490+
/** @format date-time */
491+
since?: string;
492+
status?: string;
493+
/** base64safe encoded public signing key */
494+
sub?: string;
495+
},
496+
Error
497+
>({
498+
path: \`/i_key/\${iPk}\`,
499+
method: "GET",
500+
format: "json",
501+
...params,
502+
}),
503+
504+
/**
505+
* @description Get public details of an Authentiq ID.
506+
*
507+
* @tags key, get
508+
* @name UnderlinesDetail
509+
* @request GET:/i_key/underlines/{i__UK}
510+
*/
511+
underlinesDetail: (iUk: string, params: RequestParams = {}) =>
512+
this.request<
513+
{
514+
/** base64safe encoded public signing key */
515+
sub?: string;
516+
},
517+
Error
518+
>({
519+
path: \`/i_key/underlines/\${iUk}\`,
520+
method: "GET",
521+
format: "json",
522+
...params,
523+
}),
524+
};
479525
login = {
480526
/**
481527
* @description push sign-in request See: https://github.com/skion/authentiq/wiki/JWT-Examples

tests/spec/extractRequestParams/schema.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@
5656
"required": true,
5757
"type": "string"
5858
},
59+
"i__UK": {
60+
"description": "Variable with double __ in it.",
61+
"in": "path",
62+
"name": "i__UK",
63+
"required": true,
64+
"type": "string"
65+
},
66+
"i_PK": {
67+
"description": "Public Signing Key - Authentiq ID (43 chars)",
68+
"in": "path",
69+
"name": "i_PK",
70+
"required": true,
71+
"type": "string"
72+
},
5973
"BarBaz": {
6074
"description": "bar baz",
6175
"in": "path",
@@ -424,6 +438,85 @@
424438
"tags": ["key", "put"]
425439
}
426440
},
441+
"/i_key/{i_PK}": {
442+
"get": {
443+
"description": "Get public details of an Authentiq ID.\n",
444+
"parameters": [
445+
{
446+
"$ref": "#/parameters/i_PK"
447+
}
448+
],
449+
"produces": ["application/json"],
450+
"responses": {
451+
"200": {
452+
"description": "Successfully retrieved",
453+
"schema": {
454+
"properties": {
455+
"since": {
456+
"format": "date-time",
457+
"type": "string"
458+
},
459+
"status": {
460+
"type": "string"
461+
},
462+
"sub": {
463+
"description": "base64safe encoded public signing key",
464+
"type": "string"
465+
}
466+
},
467+
"title": "JWT",
468+
"type": "object"
469+
}
470+
},
471+
"404": {
472+
"description": "Unknown key `unknown-key`",
473+
"schema": {
474+
"$ref": "#/definitions/Error"
475+
}
476+
},
477+
"410": {
478+
"description": "Key is revoked (gone). `revoked-key`",
479+
"schema": {
480+
"$ref": "#/definitions/Error"
481+
}
482+
},
483+
"default": {
484+
"$ref": "#/responses/ErrorResponse"
485+
}
486+
},
487+
"tags": ["key", "get"]
488+
}
489+
},
490+
"/i_key/underlines/{i__UK}": {
491+
"get": {
492+
"description": "Get public details of an Authentiq ID.\n",
493+
"parameters": [
494+
{
495+
"$ref": "#/parameters/i__UK"
496+
}
497+
],
498+
"produces": ["application/json"],
499+
"responses": {
500+
"200": {
501+
"description": "Successfully retrieved",
502+
"schema": {
503+
"properties": {
504+
"sub": {
505+
"description": "base64safe encoded public signing key",
506+
"type": "string"
507+
}
508+
},
509+
"title": "JWT",
510+
"type": "object"
511+
}
512+
},
513+
"default": {
514+
"$ref": "#/responses/ErrorResponse"
515+
}
516+
},
517+
"tags": ["key", "get"]
518+
}
519+
},
427520
"/login": {
428521
"post": {
429522
"consumes": ["application/jwt"],

0 commit comments

Comments
 (0)