diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d9ed33..7c0a768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Removed ### Fixed - Entities that are transitively autoexposed and should still be considered readonly, do not generate documentation for write endpoints anymore +- OpenAPI compilation is now pure: the input CSN is no longer mutated during compilation ### Security ## [1.6.0] - 2026-08-04 diff --git a/lib/compile/index.js b/lib/compile/index.js index 09753f3..a4e3f4a 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -32,6 +32,7 @@ function compileToOpenAPI(csn, options = {}) { } function processor(csn, options = {}) { + csn = cds.clone(csn); const edmOptions = { odataOpenapiHints: true, // hint to cds-compiler edm4OpenAPI: true, // downgrades certain OData errors to warnings in cds-compiler diff --git a/test/lib/compile/openapi.test.js b/test/lib/compile/openapi.test.js index a74f7be..e21e0b2 100644 --- a/test/lib/compile/openapi.test.js +++ b/test/lib/compile/openapi.test.js @@ -292,6 +292,19 @@ service CatalogService { assert(!openapi.servers[0].url.includes('odata')); }); + test('does not mutate @protocol annotation after compilation', () => { + const csn = cds.compile.to.csn(` + namespace com.sap; + @protocol: ['odata', 'rest'] + service A { entity E { key ID : UUID; }; } + `); + const originalProtocol = csn.definitions['com.sap.A']['@protocol']; + assert(Array.isArray(originalProtocol), '@protocol should be an array before compilation'); + toOpenApi(csn); + assert(Array.isArray(csn.definitions['com.sap.A']['@protocol']), + '@protocol must not be mutated by toOpenApi'); + }); + test('options: Multiple servers', () => { const csn = cds.compile.to.csn(` service A {entity E { key ID : UUID; };};`