Skip to content

Commit

Permalink
OpenAPI: Revert changes from PR #42 (#57)
Browse files Browse the repository at this point in the history
* revert commit

* Update CHANGELOG.md
  • Loading branch information
RoshniNaveenaS authored Dec 3, 2024
1 parent 2a4934c commit f3fcc81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 5 additions & 13 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/lib/compile/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});


Expand All @@ -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');
});
Expand All @@ -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', () => {
Expand Down

0 comments on commit f3fcc81

Please sign in to comment.