Skip to content

Commit

Permalink
Fix route param parsing when the param begins with just one letter
Browse files Browse the repository at this point in the history
For example if the param was i_key the current regex would not find it as a variable. it was only working for the params with more than one letter before either `.` `-` or `_`. the fix should allow to find params with only one letter at begninng.
  • Loading branch information
ahoseinian committed May 10, 2024
1 parent 4e90655 commit d10f308
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/schema-routes/schema-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SchemaRoutes {
originalRouteName;

const pathParamMatches = (routeName || "").match(
/({(([A-z]){1}([a-zA-Z0-9]-?_?\.?)+)([0-9]+)?})|(:(([A-z]){1}([a-zA-Z0-9]-?_?\.?)+)([0-9]+)?:?)/g,
/({(([A-z]){1}([a-zA-Z0-9-_.]-?_?\.?)+)([0-9]+)?})|(:(([A-z]){1}([a-zA-Z0-9-_.]-?_?\.?)+)([0-9]+)?:?)/g,
);

// used in case when path parameters is not declared in requestInfo.parameters ("in": "path")
Expand Down
25 changes: 25 additions & 0 deletions tests/spec/extractRequestParams/expected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,31 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params,
}),
};
iKey = {
/**
* @description Get public details of an Authentiq ID.
*
* @tags key, get
* @name IKeyDetail
* @request GET:/i_key/{i_PK}
*/
iKeyDetail: (iPk: string, params: RequestParams = {}) =>
this.request<
{
/** @format date-time */
since?: string;
status?: string;
/** base64safe encoded public signing key */
sub?: string;
},
Error
>({
path: `/i_key/${iPk}`,
method: "GET",
format: "json",
...params,
}),
};
login = {
/**
* @description push sign-in request See: https://github.com/skion/authentiq/wiki/JWT-Examples
Expand Down
56 changes: 56 additions & 0 deletions tests/spec/extractRequestParams/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
"required": true,
"type": "string"
},
"i_PK": {
"description": "Public Signing Key - Authentiq ID (43 chars)",
"in": "path",
"name": "i_PK",
"required": true,
"type": "string"
},
"BarBaz": {
"description": "bar baz",
"in": "path",
Expand Down Expand Up @@ -424,6 +431,55 @@
"tags": ["key", "put"]
}
},
"/i_key/{i_PK}": {
"get": {
"description": "Get public details of an Authentiq ID.\n",
"parameters": [
{
"$ref": "#/parameters/i_PK"
}
],
"produces": ["application/json"],
"responses": {
"200": {
"description": "Successfully retrieved",
"schema": {
"properties": {
"since": {
"format": "date-time",
"type": "string"
},
"status": {
"type": "string"
},
"sub": {
"description": "base64safe encoded public signing key",
"type": "string"
}
},
"title": "JWT",
"type": "object"
}
},
"404": {
"description": "Unknown key `unknown-key`",
"schema": {
"$ref": "#/definitions/Error"
}
},
"410": {
"description": "Key is revoked (gone). `revoked-key`",
"schema": {
"$ref": "#/definitions/Error"
}
},
"default": {
"$ref": "#/responses/ErrorResponse"
}
},
"tags": ["key", "get"]
}
},
"/login": {
"post": {
"consumes": ["application/jwt"],
Expand Down
25 changes: 25 additions & 0 deletions tests/spec/extractRequestParams/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,31 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params,
}),
};
iKey = {
/**
* @description Get public details of an Authentiq ID.
*
* @tags key, get
* @name IKeyDetail
* @request GET:/i_key/{i_PK}
*/
iKeyDetail: (iPk: string, params: RequestParams = {}) =>
this.request<
{
/** @format date-time */
since?: string;
status?: string;
/** base64safe encoded public signing key */
sub?: string;
},
Error
>({
path: `/i_key/${iPk}`,
method: "GET",
format: "json",
...params,
}),
};
login = {
/**
* @description push sign-in request See: https://github.com/skion/authentiq/wiki/JWT-Examples
Expand Down

0 comments on commit d10f308

Please sign in to comment.