From 0db70b6ddfc7a9e2e93b45ae52400f0e005fd0b3 Mon Sep 17 00:00:00 2001 From: Roshni Naveena S Date: Tue, 3 Dec 2024 12:30:43 +0530 Subject: [PATCH 1/2] revert commit --- lib/compile/csdl2openapi.js | 18 +++++------------- test/lib/compile/openapi.test.js | 6 +++--- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/compile/csdl2openapi.js b/lib/compile/csdl2openapi.js index 0d07f53..0477c6b 100644 --- a/lib/compile/csdl2openapi.js +++ b/lib/compile/csdl2openapi.js @@ -96,7 +96,7 @@ module.exports.csdl2openapi = function ( 'x-sap-api-type': 'ODATAV4', 'x-odata-version': csdl.$Version, 'x-sap-shortText': getShortText(csdl, entityContainer), - servers: getServers(serviceRoot, serversObject, csdl), + servers: getServers(serviceRoot, serversObject), tags: entityContainer ? getTags(entityContainer) : {}, paths: entityContainer ? getPaths(entityContainer) : {}, components: getComponents(csdl, entityContainer) @@ -564,21 +564,13 @@ module.exports.csdl2openapi = function ( * @param {object} serversObject Input servers object * @return {Array} The list of servers */ - function getServers(serviceRoot, serversObject, csdl) { + function getServers(serviceRoot, serversObject) { let servers; - - if (serversObject && csdl.$EntityContainer ) { + if (serversObject) { try { - servers = JSON.parse(serversObject); - // if csdl.$Version is 4.01 then protocol is rest if it is less than 4.01 then protocol is odata - const protocol = csdl.$Version <= "4.01" ? "odata/v4" : "rest"; - const serviceName = nameParts(csdl.$EntityContainer).qualifier; - // append /protocol/{$serviceName} to the URL - servers.forEach((server) => { - server.url = server.url + "/" + protocol + "/" + serviceName; - }); + servers = JSON.parse(serversObject); } catch (err) { - throw new Error(`The input server object is invalid.`); + throw new Error(`The input server object is invalid.`); } if (!servers.length) { diff --git a/test/lib/compile/openapi.test.js b/test/lib/compile/openapi.test.js index c79e939..46d13c8 100644 --- a/test/lib/compile/openapi.test.js +++ b/test/lib/compile/openapi.test.js @@ -254,7 +254,7 @@ service CatalogService { const serverObj = "[{\n \"url\": \"https://{customer1Id}.saas-app.com:{port}/v2\",\n \"variables\": {\n \"customer1Id\": \"demo\",\n \"description\": \"Customer1 ID assigned by the service provider\"\n }\n}, {\n \"url\": \"https://{customer2Id}.saas-app.com:{port}/v2\",\n \"variables\": {\n \"customer2Id\": \"demo\",\n \"description\": \"Customer2 ID assigned by the service provider\"\n }\n}]" const openapi = toOpenApi(csn, { 'openapi:servers': serverObj }); expect(openapi.servers).toBeTruthy(); - expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2/odata/v4/A') + expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2') }); @@ -277,7 +277,7 @@ service CatalogService { ); const openapi = toOpenApi(csn, { 'openapi:config-file': path.resolve("./test/lib/compile/data/configFile.json") }); expect(openapi.servers).toBeTruthy(); - expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080/rest/A' }, { url: "http://foo.bar:8080/a/foo/rest/A" }] }); + expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }, { url: "http://foo.bar:8080/a/foo" }] }); expect(openapi.info.description).toMatch(/yuml.*diagram/i); expect(openapi['x-odata-version']).toMatch('4.1'); }); @@ -296,7 +296,7 @@ service CatalogService { expect(openapi.info.title).toMatch(/http:\/\/example.com:8080/i) expect(openapi.info.description).not.toMatch(/yuml.*diagram/i); expect(openapi['x-odata-version']).toMatch('4.0'); - expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080/odata/v4/A' }, { url: "http://foo.bar:8080/a/foo/odata/v4/A" }] }); + expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }, { url: "http://foo.bar:8080/a/foo" }] }); }); test('annotations: root entity property', () => { From c7050848106339ab8d6175d4c3c4e27b47274f6c Mon Sep 17 00:00:00 2001 From: Roshni Naveena S Date: Tue, 3 Dec 2024 14:12:53 +0530 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c4386..618d958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). - Fixed allowedValues on all primitive types. - Removed duplicates in `tags`. +- No longer append protocol and service name information to the server URL incase of `openapi:servers` option. ## Version 1.0.7 - 17.10.2024