Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshniNaveenaS committed Aug 27, 2024
1 parent d17c92f commit e869a07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,20 @@ module.exports.csdl2openapi = function (

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';
// append /protocol/{$serviceName} to the URL
servers.forEach(server => { server.url = server.url + '/' + protocol + '/' + csdl.$EntityContainer });
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";
// append /protocol/{$serviceName} to the URL
let serviceName = csdl.$EntityContainer.includes(
".EntityContainer"
)
? csdl.$EntityContainer.replace(".EntityContainer", "")
: csdl.$EntityContainer;
servers.forEach((server) => {
server.url = server.url + "/" + protocol + "/" + serviceName;
});
} 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
2 changes: 1 addition & 1 deletion test/lib/compile/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('OpenAPI export', () => {
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.EntityContainer')
expect(openapi.servers[0].url).toMatch('https://{customer1Id}.saas-app.com:{port}/v2/odata/v4/A')
});


Expand Down

0 comments on commit e869a07

Please sign in to comment.