Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
### Deprecated
### Removed
### Fixed
- Entities that are transitively autoexposed and should still be considered readonly, do not generate documentation for write endpoints anymore
### Security

## [1.6.0] - 2026-08-04
Expand Down
10 changes: 6 additions & 4 deletions lib/compile/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ module.exports.csdl2openapi = function (
const type = fullTypeName.startsWith(`${serviceName}.`)
? fullTypeName.substring(serviceName.length + 1)
: nameParts(fullTypeName).name;
if ((csdl[serviceName]?.[type]?.['@cds.autoexpose'] || csdl[serviceName]?.[type]?.['@cds.autoexposed'])
&& (!entityContainer[type] || type.endsWith('_texts'))) {
if (csdl[serviceName]?.[type]?.['@cds.autoexpose'] || csdl[serviceName]?.[type]?.['@cds.autoexposed']) {
entityContainer[element]['$cds.autoexpose'] = true;
}
if (csdl[serviceName]?.[type]?.['@cds.autoexposed']) {
entityContainer[element]['$cds.autoexposed'] = true;
}
}
});
}
Expand Down Expand Up @@ -381,7 +383,7 @@ module.exports.csdl2openapi = function (
Object.keys(container)
.filter(name => isIdentifier(name) && container[name].$Type)
.forEach(child => {
if (child.endsWith('_texts') && container[child]['$cds.autoexpose']) {
if (container[child]['$cds.autoexposed']) {
return;
}
const type = meta.modelElement(container[child].$Type) || {};
Expand Down Expand Up @@ -426,7 +428,7 @@ module.exports.csdl2openapi = function (
const resources = Object.keys(container).filter(name => isIdentifier(name));
resources.forEach(name => {
const child = container[name];
if (name.endsWith('_texts') && child['$cds.autoexpose']) {
if (child['$cds.autoexposed']) {
return;
}
if (child.$Type) {
Expand Down
6 changes: 3 additions & 3 deletions lib/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function toOpenApiOptions(csdl, csn, options = {}) {
const result = { ...envOptions, ...fileOptions, ...callerOptions };
delete result["config-file"];

const protocols = _getProtocols(csdl, csn, result.odataVersion);
const protocols = _getProtocols(csdl, csn, result.odataVersion, result.protocol);

if (result.url) {
const servicePaths = _servicePath(csdl, csn, protocols);
Expand All @@ -143,7 +143,7 @@ function toOpenApiOptions(csdl, csn, options = {}) {
return result;
}

function _getProtocols(csdl, csn, odataVersion) {
function _getProtocols(csdl, csn, odataVersion, protocol) {
if (csdl.$EntityContainer) {
const serviceName = csdl.$EntityContainer.replace(/\.[^.]+$/, "");
const service = csn.definitions[serviceName];
Expand All @@ -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(supportedProtocols.includes(protocol) ? protocol : "odata");
} else if (service["@protocol"] === "none") {
// if @protocol is 'none' then throw an error
throw new Error(
Expand Down
16 changes: 16 additions & 0 deletions test/lib/compile/csdl2openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const result11 = require("./data/description-fallback.openapi3.json");
const example12 = require("./data/autoexposed-texts.json");
const result12 = require("./data/autoexposed-texts.openapi3.json");

const example13 = require("./data/autoexposed-direct.json");
const result13 = require("./data/autoexposed-direct.openapi3.json");

const example14 = require("./data/autoexposed-composition.json");
const result14 = require("./data/autoexposed-composition.openapi3.json");

describe("Examples", () => {
test("csdl-16.1", () => {
const openapi = lib.csdl2openapi(example1, { diagram: true });
Expand Down Expand Up @@ -103,6 +109,16 @@ describe("Examples", () => {
const openapi = lib.csdl2openapi(example12);
check(openapi, result12);
});

test("autoexposed-direct", () => {
const openapi = lib.csdl2openapi(example13, { url: "https://localhost/service-root" });
check(openapi, result13);
});

test("autoexposed-composition", () => {
const openapi = lib.csdl2openapi(example14, { url: "https://localhost/service-root" });
check(openapi, result14);
});
});

describe("Edge cases", () => {
Expand Down
47 changes: 47 additions & 0 deletions test/lib/compile/data/autoexposed-composition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$Version": "4.01",
"$EntityContainer": "MyService.EntityContainer",
"$Reference": {},
"MyService": {
"$Kind": "Schema",
"EntityContainer": {
"$Kind": "EntityContainer",
"Orders": {
"$Collection": true,
"$Type": "MyService.Orders",
"$NavigationPropertyBinding": {
"items": "OrderItems"
}
},
"OrderItems": {
"$Collection": true,
"$Type": "MyService.OrderItems"
}
},
"Orders": {
"$Kind": "EntityType",
"$Key": ["ID"],
"ID": {
"$Type": "Edm.Int32"
},
"items": {
"$Kind": "NavigationProperty",
"$Type": "MyService.OrderItems",
"$Collection": true,
"$ContainsTarget": true
}
},
"OrderItems": {
"$Kind": "EntityType",
"$Key": ["ID"],
"@cds.autoexposed": true,
"ID": {
"$Type": "Edm.Int32"
},
"quantity": {
"$Type": "Edm.Int32",
"$Nullable": true
}
}
}
}
Loading