Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
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
3 changes: 3 additions & 0 deletions bookshop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"express": "^4.17.1",
"passport": "0.4.1"
},
"devDependencies": {
"@cds/cds-plugin-openapi": "*"
},
"scripts": {
"genres": "cds serve test/genres.cds",
"start": "cds run",
Expand Down
29 changes: 29 additions & 0 deletions cds-plugin-openapi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable require-await */
const cds = require('@sap/cds'), { BuildTaskHandler } = cds.build
const cdsdk = require('@sap/cds-dk')

cds.build.register(class OpenApiHandler extends BuildTaskHandler {
static get meta() {
return {
id: 'openapi',
runWith: ['node-cf', 'java-cf'],
config: { src: cds.env.folders.srv.replace(/\/$/, '') }
}
}
async clean() {
return this.remove('openapi-docs')
}
async build() {
const model = await this.model()
const { options } = this.task

// generate openapi files for all services
await Promise.all(cds.linked(model).services.map(service => {
const openApi = cdsdk.compile.to.openapi(model, {
service: service.name,
'openapi:diagram': String(options.diagram) === 'true'
})
this.write(openApi).to(`openapi-docs/${service.name}.openapi3.json`)
}))
}
})
9 changes: 9 additions & 0 deletions cds-plugin-openapi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@sap/cds-plugin-openapi",
"version": "1.0.0",
"description": "OpenAPI service specification build plugin",
"main": "index.js",
"dependencies": {
"@sap/cds-dk": "^4"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
"@capire/media": "./media",
"@capire/orders": "./orders",
"@capire/reviews": "./reviews",
"@sap/cds": "^5.5.3"
"@sap/cds": "git+https://github.tools.sap/cap/cds#add/customBuildTaskProviders"
},
"devDependencies": {
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-subset": "^1.6.0",
"sqlite3": "^5"
"sqlite3": "^5",
"@cds/cds-plugin-openapi": "./cds-plugin-openapi"
},
"scripts": {
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
Expand Down