Skip to content

Commit bfd6d21

Browse files
Fix: Server URL update based on OData version (#58)
* Update index.js * Update CHANGELOG.md * Update openapi.test.js
1 parent ce03f30 commit bfd6d21

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## Version 1.1.1 - tbd
8+
9+
### Fixed
10+
11+
- Fixes server URL based on the version provided by `--odata-version` value.
12+
713
## Version 1.1.0 - 04.12.2024
814

915
### Added

lib/compile/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function toOpenApiOptions(csdl, csn, options = {}) {
106106
}
107107
}
108108

109-
const protocols = _getProtocols(csdl, csn);
109+
const protocols = _getProtocols(csdl, csn, result["odataVersion"]);
110110

111111
if (result.url) {
112112
const servicePaths = _servicePath(csdl, csn, protocols);
@@ -127,13 +127,19 @@ function toOpenApiOptions(csdl, csn, options = {}) {
127127
return result;
128128
}
129129

130-
function _getProtocols(csdl, csn) {
130+
function _getProtocols(csdl, csn, odataVersion) {
131131
if (csdl.$EntityContainer) {
132132
const serviceName = csdl.$EntityContainer.replace(/\.[^.]+$/, "");
133133
const service = csn.definitions[serviceName];
134134
let protocols = [];
135135

136-
if (!service["@protocol"]) {
136+
if(odataVersion === "4.01"){
137+
protocols.push("rest");
138+
}
139+
else if(odataVersion === "4.0"){
140+
protocols.push("odata");
141+
}
142+
else if (!service["@protocol"]) {
137143
protocols.push("rest"); //taking rest as default in case no relevant protocol is there
138144
} else if (service["@protocol"] === "none") {
139145
// if @protocol is 'none' then throw an error

test/lib/compile/openapi.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ service CatalogService {
247247
expect(openapi.servers).toBeTruthy();
248248
});
249249

250+
test('options: odata-version check server URL', () => {
251+
const csn = cds.compile.to.csn(`
252+
service A {entity E { key ID : UUID; };};`
253+
);
254+
const openapi = toOpenApi(csn, { 'odata-version': '4.0' });
255+
expect(openapi.servers[0].url).toMatch('odata');
256+
});
257+
250258
test('options: Multiple servers', () => {
251259
const csn = cds.compile.to.csn(`
252260
service A {entity E { key ID : UUID; };};`

0 commit comments

Comments
 (0)