From e8c19f44e5583a70aeb177f0b11b50b6fff74a39 Mon Sep 17 00:00:00 2001 From: Filipe Freire Date: Wed, 30 Mar 2022 14:31:15 +0100 Subject: [PATCH] Reproduce and Fix #4432 (#4657) * Add failing fixtures that repro #4432 * Add test for generateSlug * Fix #4432. Pin slugify to 1.6.5. --- packages/openapi-2-kong/package-lock.json | 16 ++++----- packages/openapi-2-kong/package.json | 2 +- packages/openapi-2-kong/src/common.test.ts | 1 + .../fixtures/api-with-examples.expected.json | 2 +- .../dash-and-underscore.expected.json | 33 +++++++++++++++++++ .../fixtures/dash-and-underscore.yaml | 13 ++++++++ .../fixtures/httpbin.expected.json | 28 ++++++++-------- .../fixtures/no-targets-example.expected.json | 2 +- .../fixtures/openapi-303.expected.json | 3 +- .../request-validator-plugin.expected.json | 2 +- .../fixtures/security.expected.json | 12 +++---- .../fixtures/uspto.expected.json | 6 ++-- .../src/declarative-config/names.test.ts | 8 ++--- .../src/declarative-config/services.test.ts | 4 +-- 14 files changed, 89 insertions(+), 43 deletions(-) create mode 100644 packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.expected.json create mode 100644 packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.yaml diff --git a/packages/openapi-2-kong/package-lock.json b/packages/openapi-2-kong/package-lock.json index f7af1ec64d..f689e9de0b 100644 --- a/packages/openapi-2-kong/package-lock.json +++ b/packages/openapi-2-kong/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "openapi-types": "^8.0.0", - "slugify": "^1.3.6", + "slugify": "1.6.5", "swagger-parser": "^10.0.3", "url-join": "^4.0.1", "yaml": "2.0.0-5" @@ -7015,11 +7015,11 @@ } }, "node_modules/slugify": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.6.tgz", - "integrity": "sha512-wA9XS475ZmGNlEnYYLPReSfuz/c3VQsEMoU43mi6OnKMCdbnFXd4/Yg7J0lBv8jkPolacMpOrWEaoYxuE1+hoQ==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.5.tgz", + "integrity": "sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ==", "engines": { - "node": ">=4.0.0" + "node": ">=8.0.0" } }, "node_modules/snapdragon": { @@ -13693,9 +13693,9 @@ "dev": true }, "slugify": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.3.6.tgz", - "integrity": "sha512-wA9XS475ZmGNlEnYYLPReSfuz/c3VQsEMoU43mi6OnKMCdbnFXd4/Yg7J0lBv8jkPolacMpOrWEaoYxuE1+hoQ==" + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.5.tgz", + "integrity": "sha512-8mo9bslnBO3tr5PEVFzMPIWwWnipGS0xVbYf65zxDqfNwmzYn1LpiKNrR6DlClusuvo+hDHd1zKpmfAe83NQSQ==" }, "snapdragon": { "version": "0.8.2", diff --git a/packages/openapi-2-kong/package.json b/packages/openapi-2-kong/package.json index 3b9005c860..57ee735978 100644 --- a/packages/openapi-2-kong/package.json +++ b/packages/openapi-2-kong/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "openapi-types": "^8.0.0", - "slugify": "^1.3.6", + "slugify": "1.6.5", "swagger-parser": "^10.0.3", "url-join": "^4.0.1", "yaml": "2.0.0-5" diff --git a/packages/openapi-2-kong/src/common.test.ts b/packages/openapi-2-kong/src/common.test.ts index 6126d322e2..ef75653066 100644 --- a/packages/openapi-2-kong/src/common.test.ts +++ b/packages/openapi-2-kong/src/common.test.ts @@ -177,6 +177,7 @@ describe('common', () => { expect(generateSlug('foo bar')).toBe('foo_bar'); expect(generateSlug('foo, bar')).toBe('foo_bar'); expect(generateSlug('Foo Bar')).toBe('Foo_Bar'); + expect(generateSlug('Foo-Bar')).toBe('Foo-Bar'); expect( generateSlug('foo bar', { replacement: '?', diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/api-with-examples.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/api-with-examples.expected.json index b080e5d99f..b1d81c8838 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/api-with-examples.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/api-with-examples.expected.json @@ -16,7 +16,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_api-with-examples.yaml"], - "name": "Simple_API_overview-x_kong_name_override_at_method", + "name": "Simple_API_overview-x-kong-name-override-at-method", "paths": ["/$"] }, { diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.expected.json new file mode 100644 index 0000000000..b64da33825 --- /dev/null +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.expected.json @@ -0,0 +1,33 @@ +{ + "_format_version": "1.1", + "services": [ + { + "name": "Sample-API", + "protocol": "https", + "host": "example.com", + "port": 443, + "path": "/", + "plugins": [], + "routes": [ + { + "tags": [ + "OAS3_import", + "OAS3file_dash-and-underscore.yaml" + ], + "name": "Sample-API-list-get", + "methods": [ + "GET" + ], + "paths": [ + "/list$" + ], + "strip_path": false + } + ], + "tags": [ + "OAS3_import", + "OAS3file_dash-and-underscore.yaml" + ] + } + ] +} diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.yaml b/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.yaml new file mode 100644 index 0000000000..621b31599d --- /dev/null +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/dash-and-underscore.yaml @@ -0,0 +1,13 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Sample-API +servers: + - url: https://example.com +paths: + /list: + get: + description: Returns a list of stuff + responses: + '200': + description: Successful response diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/httpbin.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/httpbin.expected.json index 5a6a619381..278c5aef4b 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/httpbin.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/httpbin.expected.json @@ -19,7 +19,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-basic_auth_user_password-get", + "name": "httpbin-basic-auth-user-password-get", "plugins": [ { "config": { "hide_credentials": true }, @@ -33,14 +33,14 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-image_format-get", + "name": "httpbin-image-format-get", "paths": ["/image/(?[^\\/]+)$"] }, { "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-delay_n-get", + "name": "httpbin-delay-n-get", "paths": ["/delay/(?[^\\/]+)$"] }, { @@ -54,49 +54,49 @@ "methods": ["DELETE"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-status_statusCode-delete", + "name": "httpbin-status-statusCode-delete", "paths": ["/status/(?[^\\/]+)$"] }, { "methods": ["PUT"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-status_statusCode-put", + "name": "httpbin-status-statusCode-put", "paths": ["/status/(?[^\\/]+)$"] }, { "methods": ["PATCH"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-status_statusCode-patch", + "name": "httpbin-status-statusCode-patch", "paths": ["/status/(?[^\\/]+)$"] }, { "methods": ["POST"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-status_statusCode-post", + "name": "httpbin-status-statusCode-post", "paths": ["/status/(?[^\\/]+)$"] }, { "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-status_statusCode-get", + "name": "httpbin-status-statusCode-get", "paths": ["/status/(?[^\\/]+)$"] }, { "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-user_agent-get", + "name": "httpbin-user-agent-get", "paths": ["/user-agent$"] }, { "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-hidden_basic_auth_user_password-get", + "name": "httpbin-hidden-basic-auth-user-password-get", "plugins": [ { "config": { "hide_credentials": true }, @@ -146,7 +146,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-cookies_delete-get", + "name": "httpbin-cookies-delete-get", "paths": ["/cookies/delete$"] }, { @@ -160,7 +160,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-parse_machine_timestamp-get", + "name": "httpbin-parse-machine_timestamp-get", "paths": ["/parse/(?[^\\/]+)$"] }, { @@ -188,7 +188,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-when_human_timestamp-get", + "name": "httpbin-when-human_timestamp-get", "plugins": [ { "name": "request-validator", @@ -236,7 +236,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_httpbin.yaml"], - "name": "httpbin-cookies_set-get", + "name": "httpbin-cookies-set-get", "paths": ["/cookies/set$"] } ], diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/no-targets-example.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/no-targets-example.expected.json index dfd5bd6ac4..5898a5fac7 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/no-targets-example.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/no-targets-example.expected.json @@ -12,7 +12,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_no-targets-example.yaml"], - "name": "Simple_API_overview-x_kong_name_override_at_method", + "name": "Simple_API_overview-x-kong-name-override-at-method", "paths": ["/$"] }, { diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/openapi-303.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/openapi-303.expected.json index a2a231bea9..c1746f90e7 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/openapi-303.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/openapi-303.expected.json @@ -15,5 +15,4 @@ ] } ] - } - \ No newline at end of file + } diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/request-validator-plugin.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/request-validator-plugin.expected.json index e3b3d917c3..aa9bcb2afc 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/request-validator-plugin.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/request-validator-plugin.expected.json @@ -59,7 +59,7 @@ }, { "methods": ["GET"], - "name": "Example-params_pathid-get", + "name": "Example-params-pathid-get", "paths": ["/params/(?[^\\/]+)/$"], "plugins": [ { diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/security.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/security.expected.json index a0b1a275dd..9133ed0fb0 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/security.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/security.expected.json @@ -12,7 +12,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-only_oath2-get", + "name": "Security_Example-only-oath2-get", "plugins": [ { "config": { "auth_methods": ["client_credentials"] }, @@ -26,7 +26,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-only_key-get", + "name": "Security_Example-only-key-get", "plugins": [ { "config": { "key_names": ["api_key_by_me"] }, @@ -40,7 +40,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-and_based_auth-get", + "name": "Security_Example-and-based-auth-get", "plugins": [ { "config": { "auth_methods": ["client_credentials"] }, @@ -54,7 +54,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-or_based_auth-get", + "name": "Security_Example-or-based-auth-get", "plugins": [ { "config": { "key_names": ["api_key_by_me"] }, @@ -68,7 +68,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-only_oidc-get", + "name": "Security_Example-only-oidc-get", "plugins": [ { "config": { @@ -85,7 +85,7 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_security.yaml"], - "name": "Security_Example-only_basic-get", + "name": "Security_Example-only-basic-get", "plugins": [ { "name": "basic-auth", diff --git a/packages/openapi-2-kong/src/declarative-config/fixtures/uspto.expected.json b/packages/openapi-2-kong/src/declarative-config/fixtures/uspto.expected.json index 5d5112a4c4..b21b2dffec 100644 --- a/packages/openapi-2-kong/src/declarative-config/fixtures/uspto.expected.json +++ b/packages/openapi-2-kong/src/declarative-config/fixtures/uspto.expected.json @@ -12,21 +12,21 @@ "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_uspto.yaml"], - "name": "USPTO_Data_Set_API-list_data_sets", + "name": "USPTO_Data_Set_API-list-data-sets", "paths": ["/$"] }, { "methods": ["GET"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_uspto.yaml"], - "name": "USPTO_Data_Set_API-list_searchable_fields", + "name": "USPTO_Data_Set_API-list-searchable-fields", "paths": ["/(?[^\\/]+)/(?[^\\/]+)/fields$"] }, { "methods": ["POST"], "strip_path": false, "tags": ["OAS3_import", "OAS3file_uspto.yaml"], - "name": "USPTO_Data_Set_API-perform_search", + "name": "USPTO_Data_Set_API-perform-search", "paths": ["/(?[^\\/]+)/(?[^\\/]+)/records$"] } ], diff --git a/packages/openapi-2-kong/src/declarative-config/names.test.ts b/packages/openapi-2-kong/src/declarative-config/names.test.ts index f138a49d59..ad9e6f6b2f 100644 --- a/packages/openapi-2-kong/src/declarative-config/names.test.ts +++ b/packages/openapi-2-kong/src/declarative-config/names.test.ts @@ -35,7 +35,7 @@ const compare = (expected: string, pathItem: OA3PathItem) => { describe('names', () => { it("api.paths[path][method]['x-kong-name'] is highest priority", () => { - compare('Nebulo_9-method_smash', { + compare('Nebulo_9-method-smash', { [xKongName]: 'pathItem-smash', post: { [xKongName]: 'method-smash', @@ -45,7 +45,7 @@ describe('names', () => { }); it('api.paths[path][method].operationId is second priority (and not slugified)', () => { - compare('Nebulo_9-operationId_smash', { + compare('Nebulo_9-operationId-smash', { [xKongName]: 'pathItem-smash', post: { operationId: 'operationId-smash', @@ -54,14 +54,14 @@ describe('names', () => { }); it("api.paths[path]['x-kong-name'] is third priority", () => { - compare('Nebulo_9-pathItem_smash-post', { + compare('Nebulo_9-pathItem-smash-post', { [xKongName]: 'pathItem-smash', post: {}, }); }); it('purely generated is fourth priority', () => { - compare('Nebulo_9-planet_smasher-post', { + compare('Nebulo_9-planet-smasher-post', { post: {}, }); }); diff --git a/packages/openapi-2-kong/src/declarative-config/services.test.ts b/packages/openapi-2-kong/src/declarative-config/services.test.ts index c99ea7e888..265f25ce0c 100644 --- a/packages/openapi-2-kong/src/declarative-config/services.test.ts +++ b/packages/openapi-2-kong/src/declarative-config/services.test.ts @@ -38,7 +38,7 @@ const getSpecResult = (): DCService => tags, }, { - name: 'My_API-birds_id-get', + name: 'My_API-birds-id-get', strip_path: false, methods: ['GET'], paths: ['/birds/(?[^\\/]+)$'], @@ -251,7 +251,7 @@ describe('services', () => { }, { tags, - name: 'My_API-birds_id-get', + name: 'My_API-birds-id-get', methods: ['GET'], paths: ['/birds/(?[^\\/]+)$'], strip_path: false,