diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3463f..e21a7f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). - Use Swagger UI 5 - Drop Node 14 support +### Added + +- New option `odataVersion` to specify the OData version used to compile the OpenAPI specs + ### Fixed - Works with `@sap/cds` 7.4 again diff --git a/README.md b/README.md index c20fef8..26f5f4a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Call `cds_swagger ({...})` with the following object as first parameter: { "basePath": "/$api-docs", // the root path to mount the middleware on "apiPath": "", // the root path for the services (useful if behind a reverse proxy) - "diagram": true // whether to render the YUML diagram + "diagram": true, // whether to render the YUML diagram + "odataVersion": "4.0" // specify the OData Version used by cds-dk (>=7.2.0) to compile the OpenAPI specs. When undefined, this defaults to 4.01 } ``` diff --git a/index.js b/index.js index 5021255..c713de4 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,7 @@ function toOpenApiDoc (service, options = {}) { if (!cache[service.name]) { cache[service.name] = cds.compile.to.openapi(service.model, { service: service.name, + 'odata-version': options.odataVersion, 'openapi:url': join('/', options.apiPath, service.path), 'openapi:diagram': ('diagram' in options ? options.diagram : true), to: 'openapi' // workaround needed for cds-dk 7.4 @@ -58,4 +59,5 @@ function addLinkToIndexHtml (service, apiPath) { * @property {string} basePath - the root path to mount the middleware on * @property {string} apiPath - the root path for the services (useful if behind a reverse proxy) * @property {boolean} diagram - whether to render the YUML diagram + * @property {string} odataVersion - the OData version used to compile the OpenAPI specs. Defaults to 4.01 */ diff --git a/tests/server-options.test.js b/tests/server-options.test.js index 1d5d24d..e09309c 100644 --- a/tests/server-options.test.js +++ b/tests/server-options.test.js @@ -1,7 +1,7 @@ -process.env.TEST_OPTIONS = JSON.stringify({basePath:'/test-base', apiPath: '/root', diagram:false}) +process.env.TEST_OPTIONS = JSON.stringify({basePath:'/test-base', apiPath: '/root', diagram:false, odataVersion:'4.0'}) process.env.TEST_OPTIONS_UI = JSON.stringify({customSiteTitle: 'My Custom Title'}) -const cds = require('@sap/cds/lib') +const cds = require('@sap/cds') const { GET, expect } = cds.test.in(__dirname, 'app').run('serve', 'all') describe('with options', ()=>{