Skip to content

Commit

Permalink
feat: add OData Version to options (#71)
Browse files Browse the repository at this point in the history
* feat: add OData Version to options
* chore: update README
* Cosmetics

---------

Co-authored-by: Christian Georgi <[email protected]>
  • Loading branch information
kyc3 and chgeo authored Dec 4, 2023
1 parent 74a1887 commit 8d26473
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
4 changes: 2 additions & 2 deletions tests/server-options.test.js
Original file line number Diff line number Diff line change
@@ -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', ()=>{
Expand Down

0 comments on commit 8d26473

Please sign in to comment.