From fd18c23094e8f0bb3a636c0a9be1c263273bb61f Mon Sep 17 00:00:00 2001 From: Amir Hoseinian Date: Sun, 28 Apr 2024 16:39:36 +0200 Subject: [PATCH] Update the regex to be more concise and inclue 1 letter params https://github.com/acacode/swagger-typescript-api/pull/686#issuecomment-2067162950 --- src/schema-routes/schema-routes.js | 2 +- tests/spec/extractRequestParams/expected.ts | 21 ++++++++++++ tests/spec/extractRequestParams/schema.json | 37 +++++++++++++++++++++ tests/spec/extractRequestParams/schema.ts | 21 ++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/schema-routes/schema-routes.js b/src/schema-routes/schema-routes.js index c0dac382..2435e642 100644 --- a/src/schema-routes/schema-routes.js +++ b/src/schema-routes/schema-routes.js @@ -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-zA-Z]([a-zA-Z0-9-_.])*})|(:[a-zA-Z]([-_.]?[a-zA-Z0-9-_.])*:?)/g, ); // used in case when path parameters is not declared in requestInfo.parameters ("in": "path") diff --git a/tests/spec/extractRequestParams/expected.ts b/tests/spec/extractRequestParams/expected.ts index 58667e22..f6994d97 100644 --- a/tests/spec/extractRequestParams/expected.ts +++ b/tests/spec/extractRequestParams/expected.ts @@ -496,6 +496,27 @@ export class Api extends HttpClient + this.request< + { + /** base64safe encoded public signing key */ + sub?: string; + }, + Error + >({ + path: `/i_key/underlines/${iUk}`, + method: "GET", + format: "json", + ...params, + }), }; login = { /** diff --git a/tests/spec/extractRequestParams/schema.json b/tests/spec/extractRequestParams/schema.json index a3982337..8d4d5098 100644 --- a/tests/spec/extractRequestParams/schema.json +++ b/tests/spec/extractRequestParams/schema.json @@ -56,6 +56,13 @@ "required": true, "type": "string" }, + "i__UK": { + "description": "Variable with double __ in it.", + "in": "path", + "name": "i__UK", + "required": true, + "type": "string" + }, "i_PK": { "description": "Public Signing Key - Authentiq ID (43 chars)", "in": "path", @@ -480,6 +487,36 @@ "tags": ["key", "get"] } }, + "/i_key/underlines/{i__UK}": { + "get": { + "description": "Get public details of an Authentiq ID.\n", + "parameters": [ + { + "$ref": "#/parameters/i__UK" + } + ], + "produces": ["application/json"], + "responses": { + "200": { + "description": "Successfully retrieved", + "schema": { + "properties": { + "sub": { + "description": "base64safe encoded public signing key", + "type": "string" + } + }, + "title": "JWT", + "type": "object" + } + }, + "default": { + "$ref": "#/responses/ErrorResponse" + } + }, + "tags": ["key", "get"] + } + }, "/login": { "post": { "consumes": ["application/jwt"], diff --git a/tests/spec/extractRequestParams/schema.ts b/tests/spec/extractRequestParams/schema.ts index 58667e22..f6994d97 100644 --- a/tests/spec/extractRequestParams/schema.ts +++ b/tests/spec/extractRequestParams/schema.ts @@ -496,6 +496,27 @@ export class Api extends HttpClient + this.request< + { + /** base64safe encoded public signing key */ + sub?: string; + }, + Error + >({ + path: `/i_key/underlines/${iUk}`, + method: "GET", + format: "json", + ...params, + }), }; login = { /**