From 92ed984017490fefbd72f8823db4fbae3eff2a9f Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 29 Sep 2023 14:48:50 +0200 Subject: [PATCH] fix regex names --- .../oas3_testfiles/12-path-parameter-regex.expected.json | 6 +++--- openapi2kong/openapi2kong.go | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/openapi2kong/oas3_testfiles/12-path-parameter-regex.expected.json b/openapi2kong/oas3_testfiles/12-path-parameter-regex.expected.json index 2329775..042d662 100644 --- a/openapi2kong/oas3_testfiles/12-path-parameter-regex.expected.json +++ b/openapi2kong/oas3_testfiles/12-path-parameter-regex.expected.json @@ -34,7 +34,7 @@ ], "name": "Path_parameter_test-getBatchWithParams", "paths": [ - "~/batchs\\(Material='(?\u003cMaterial\u003e[^#?/]+)',Batch='(?\u003cBatch\u003e[^#?/]+)'\\)$" + "~/batchs\\(Material='(?\u003cmaterial\u003e[^#?/]+)',Batch='(?\u003cbatch\u003e[^#?/]+)'\\)$" ], "plugins": [], "regex_priority": 100, @@ -51,7 +51,7 @@ ], "name": "Path_parameter_test-postBatchWithParams", "paths": [ - "~/batchs\\(Material='(?\u003cMaterial\u003e[^#?/]+)',Batch='(?\u003cBatch\u003e[^#?/]+)'\\)$" + "~/batchs\\(Material='(?\u003cmaterial\u003e[^#?/]+)',Batch='(?\u003cbatch\u003e[^#?/]+)'\\)$" ], "plugins": [], "regex_priority": 100, @@ -68,7 +68,7 @@ ], "name": "Path_parameter_test-opsid", "paths": [ - "~/demo/(?\u003csomething\u003e[^#?/]+)/else/(?\u003ca_to_do\u003e[^#?/]+)/$" + "~/demo/(?\u003csomething\u003e[^#?/]+)/else/(?\u003cto_do\u003e[^#?/]+)/$" ], "plugins": [], "regex_priority": 100, diff --git a/openapi2kong/openapi2kong.go b/openapi2kong/openapi2kong.go index a8c5e49..9dfb6c6 100644 --- a/openapi2kong/openapi2kong.go +++ b/openapi2kong/openapi2kong.go @@ -53,6 +53,8 @@ func Slugify(name ...string) string { // The returned name will be valid for PCRE regex captures; Alphanumeric + '_', starting // with [a-zA-Z]. func sanitizeRegexCapture(varName string) string { + slugify.ToLower = true + slugify.Separator = "-" varName = slugify.Slugify(varName) varName = strings.ReplaceAll(varName, "-", "_") if strings.HasPrefix(varName, "_") {