diff --git a/CHANGELOG.md b/CHANGELOG.md index 4285a52..267c2a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Deprecated ### Removed ### Fixed +- set `odata` as the service protocol if no protocol is set to match the default behavior of `@sap/cds` ### Security ## [1.6.0] - 2026-08-04 diff --git a/lib/compile/index.js b/lib/compile/index.js index 1bfb40f..6dabd6d 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -156,7 +156,7 @@ function _getProtocols(csdl, csn, odataVersion) { protocols.push("odata"); } else if (!service["@protocol"]) { - protocols.push("rest"); //taking rest as default in case no relevant protocol is there + protocols.push("odata"); // matches cds's default protocol when none is annotated } else if (service["@protocol"] === "none") { // if @protocol is 'none' then throw an error throw new Error( diff --git a/test/lib/compile/openapi.test.js b/test/lib/compile/openapi.test.js index 79e5374..24961dd 100644 --- a/test/lib/compile/openapi.test.js +++ b/test/lib/compile/openapi.test.js @@ -262,6 +262,21 @@ service CatalogService { assert(openapi.servers[0].url.includes('odata')); }); + test('default service without @protocol renders server URL with odata/v4', () => { + const csn = cds.compile.to.csn(` + @path: 'catalog' + service CatalogService { + entity Books { + key ID : Integer; + title : String; + } + }` + ); + const openapi = toOpenApi(csn); + assert(openapi.servers[0].url.includes('odata/v4')); + assert(!openapi.servers[0].url.includes('rest')); + }); + test('options: Multiple servers', () => { const csn = cds.compile.to.csn(` service A {entity E { key ID : UUID; };};`