Skip to content
Open
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
24 changes: 16 additions & 8 deletions lib/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const csdl2openapi = require('./csdl2openapi')
const cds = require('@sap/cds/lib');
const fs = require("fs");
const DEBUG = cds.debug('openapi');
const supportedProtocols = ["rest", "odata", "odata-v4"];

module.exports = function processor(csn, options = {}) {
const edmOptions = Object.assign({
Expand Down Expand Up @@ -148,17 +149,24 @@ function _getProtocols(csdl, csn, odataVersion) {
throw new Error(
`Service "${serviceName}" is annotated with @protocol:'none' which is not supported in openAPI generation.`
);
} else if (
service["@protocol"] === "rest" ||
service["@protocol"] === "odata" || service["@protocol"] === "odata-v4"
) {
} else if (supportedProtocols.includes(service["@protocol"])) {
protocols.push(service["@protocol"]);
} else if (Array.isArray(service["@protocol"])) {
service["@protocol"].forEach((protocol) => {
if (protocol === "rest" || protocol === "odata" || protocol === "odata-v4") {
protocols.push(protocol);
if(typeof protocol === "string"){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like odata-v4 got lost?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if (supportedProtocols.includes(protocol)) {
protocols.push(protocol);
} else {
DEBUG?.(`"${protocol}" protocol is not supported`);
}
} else if (typeof protocol === "object" && !Array.isArray(protocol) && protocol !== null) {
if(supportedProtocols.includes(protocol.kind)) {
protocols.push(protocol.kind);
} else {
DEBUG?.(`"${protocol.kind}" protocol is not supported`);
}
} else {
DEBUG?.(`"${protocol}" protocol is not supported`);
DEBUG?.(`incorrect ${protocol} type`)
}
});
}
Expand All @@ -184,4 +192,4 @@ function _servicePath(csdl, csn, protocols) {

return paths;
}
}
}