Skip to content

Commit f3fcc81

Browse files
OpenAPI: Revert changes from PR #42 (#57)
* revert commit * Update CHANGELOG.md
1 parent 2a4934c commit f3fcc81

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1414

1515
- Fixed allowedValues on all primitive types.
1616
- Removed duplicates in `tags`.
17+
- No longer append protocol and service name information to the server URL incase of `openapi:servers` option.
1718

1819
## Version 1.0.7 - 17.10.2024
1920

lib/compile/csdl2openapi.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports.csdl2openapi = function (
9696
'x-sap-api-type': 'ODATAV4',
9797
'x-odata-version': csdl.$Version,
9898
'x-sap-shortText': getShortText(csdl, entityContainer),
99-
servers: getServers(serviceRoot, serversObject, csdl),
99+
servers: getServers(serviceRoot, serversObject),
100100
tags: entityContainer ? getTags(entityContainer) : {},
101101
paths: entityContainer ? getPaths(entityContainer) : {},
102102
components: getComponents(csdl, entityContainer)
@@ -564,21 +564,13 @@ module.exports.csdl2openapi = function (
564564
* @param {object} serversObject Input servers object
565565
* @return {Array} The list of servers
566566
*/
567-
function getServers(serviceRoot, serversObject, csdl) {
567+
function getServers(serviceRoot, serversObject) {
568568
let servers;
569-
570-
if (serversObject && csdl.$EntityContainer ) {
569+
if (serversObject) {
571570
try {
572-
servers = JSON.parse(serversObject);
573-
// if csdl.$Version is 4.01 then protocol is rest if it is less than 4.01 then protocol is odata
574-
const protocol = csdl.$Version <= "4.01" ? "odata/v4" : "rest";
575-
const serviceName = nameParts(csdl.$EntityContainer).qualifier;
576-
// append /protocol/{$serviceName} to the URL
577-
servers.forEach((server) => {
578-
server.url = server.url + "/" + protocol + "/" + serviceName;
579-
});
571+
servers = JSON.parse(serversObject);
580572
} catch (err) {
581-
throw new Error(`The input server object is invalid.`);
573+
throw new Error(`The input server object is invalid.`);
582574
}
583575

584576
if (!servers.length) {

test/lib/compile/openapi.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ service CatalogService {
254254
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}]"
255255
const openapi = toOpenApi(csn, { 'openapi:servers': serverObj });
256256
expect(openapi.servers).toBeTruthy();
257-
expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2/odata/v4/A')
257+
expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2')
258258
});
259259

260260

@@ -277,7 +277,7 @@ service CatalogService {
277277
);
278278
const openapi = toOpenApi(csn, { 'openapi:config-file': path.resolve("./test/lib/compile/data/configFile.json") });
279279
expect(openapi.servers).toBeTruthy();
280-
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080/rest/A' }, { url: "http://foo.bar:8080/a/foo/rest/A" }] });
280+
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }, { url: "http://foo.bar:8080/a/foo" }] });
281281
expect(openapi.info.description).toMatch(/yuml.*diagram/i);
282282
expect(openapi['x-odata-version']).toMatch('4.1');
283283
});
@@ -296,7 +296,7 @@ service CatalogService {
296296
expect(openapi.info.title).toMatch(/http:\/\/example.com:8080/i)
297297
expect(openapi.info.description).not.toMatch(/yuml.*diagram/i);
298298
expect(openapi['x-odata-version']).toMatch('4.0');
299-
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080/odata/v4/A' }, { url: "http://foo.bar:8080/a/foo/odata/v4/A" }] });
299+
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }, { url: "http://foo.bar:8080/a/foo" }] });
300300
});
301301

302302
test('annotations: root entity property', () => {

0 commit comments

Comments
 (0)