Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit e16dddd

Browse files
committed
lookupTasks becomes optional
- change output dir
1 parent 8b0f601 commit e16dddd

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

cds-plugin-openapi/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const path = require("path")
33
const fs = require("fs")
44
const cds = require('@sap/cds'), { BuildTaskProvider, BuildTaskHandler } = cds.build
55
const cdsdk = require('@sap/cds-dk')
6-
const { path4 } = cds.serve
76
const logger = cds.log("build")
87

98
module.exports.activate = () => {
@@ -18,15 +17,10 @@ module.exports.activate = () => {
1817
applyTaskDefaults(task) {
1918
task.src = task.src || cds.env.folders.srv.replace(/\/$/, '')
2019
}
21-
async lookupTasks() {
22-
if (process.env.NODE_ENV === 'production') {
23-
return [{ for: this.id }]
24-
}
25-
}
2620
get handler() {
2721
return class extends BuildTaskHandler {
2822
async clean() {
29-
fs.rm(path.join(this.task.dest, "gen/docs"), { recursive: true, force: true }, (err) => logger.error(err))
23+
fs.rm(path.join(this.task.dest, "openapi-docs"), { recursive: true, force: true }, (err) => logger.error(err))
3024
}
3125

3226
async build() {
@@ -37,15 +31,24 @@ module.exports.activate = () => {
3731
await Promise.all(cds.linked(model).services.map(service => {
3832
const openApi = cdsdk.compile.to.openapi(model, {
3933
service: service.name,
40-
'openapi:url': path4(service).replace(/\.[^.]+$/, ''),
4134
'openapi:diagram': options.diagram
4235
})
4336

44-
this.write(openApi).to(`gen/docs/${service.name}.openapi3.json`)
37+
this.write(openApi).to(`openapi-docs/${service.name}.openapi3.json`)
4538
}))
4639
}
4740
}
4841
}
42+
/**
43+
* Additional constraints can be defined, e.g. generate openapi service specification in production builds only.
44+
* > cds build --production
45+
* > cds build --for node-cf --production
46+
*/
47+
// async lookupTasks() {
48+
// if (process.env.NODE_ENV === 'production') {
49+
// return [{ for: this.id }]
50+
// }
51+
// }
4952
})()
5053
)
5154
}

0 commit comments

Comments
 (0)