diff --git a/lib/compile/index.js b/lib/compile/index.js index 9c522b3..3fa8f7c 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -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({ @@ -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"){ + 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`) } }); } @@ -184,4 +192,4 @@ function _servicePath(csdl, csn, protocols) { return paths; } -} \ No newline at end of file +}