From 419a0f654a41cdc050c9a24fdd9a0bf0385d32af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hus=C3=A1k?= Date: Wed, 20 Jul 2022 16:29:43 +0200 Subject: [PATCH] Keep x-args in securitySchema flow when converting OA3 to SW2 --- lib/converters/openapi3_to_swagger2.js | 6 ++++++ test/input/openapi_3/petstore.json | 3 ++- test/output/swagger_2/petstore_from_oas3.json | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/converters/openapi3_to_swagger2.js b/lib/converters/openapi3_to_swagger2.js index 49d2ba22..d7cf2ef5 100644 --- a/lib/converters/openapi3_to_swagger2.js +++ b/lib/converters/openapi3_to_swagger2.js @@ -524,6 +524,12 @@ Converter.prototype.convertSecurityDefinitions = function() { security.tokenUrl = flow.tokenUrl; security.scopes = flow.scopes; delete security.flows; + // copy x- args from the flow as they are + Object.keys(flow).forEach(function (k) { + if (/^x-/i.test(k)) { + security[k] = flow[k] + } + }) } } delete this.spec.components.securitySchemes; diff --git a/test/input/openapi_3/petstore.json b/test/input/openapi_3/petstore.json index 2078a9b6..fe76f7e6 100644 --- a/test/input/openapi_3/petstore.json +++ b/test/input/openapi_3/petstore.json @@ -247,7 +247,8 @@ "read:pets": "Read your pets", "write:pets": "Modify pets in your account" }, - "tokenUrl": "http://petstore.swagger.wordnik.com/api/oauth/token" + "tokenUrl": "http://petstore.swagger.wordnik.com/api/oauth/token", + "x-pet-lover-validator": "On" } }, "type": "oauth2" diff --git a/test/output/swagger_2/petstore_from_oas3.json b/test/output/swagger_2/petstore_from_oas3.json index a741c07a..70035a55 100644 --- a/test/output/swagger_2/petstore_from_oas3.json +++ b/test/output/swagger_2/petstore_from_oas3.json @@ -1074,7 +1074,8 @@ "write:pets": "Modify pets in your account" }, "tokenUrl": "http://petstore.swagger.wordnik.com/api/oauth/token", - "type": "oauth2" + "type": "oauth2", + "x-pet-lover-validator": "On" }, "oauth2_implicit": { "authorizationUrl": "http://petstore.swagger.wordnik.com/api/oauth/dialog",