From e16ddddc8c1b38bc76c0dbd2c94730a39abf98a1 Mon Sep 17 00:00:00 2001 From: Lothar Bender Date: Wed, 24 Nov 2021 09:57:25 +0100 Subject: [PATCH] lookupTasks becomes optional - change output dir --- cds-plugin-openapi/index.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cds-plugin-openapi/index.js b/cds-plugin-openapi/index.js index 1ac184ed9..d823bb1a7 100644 --- a/cds-plugin-openapi/index.js +++ b/cds-plugin-openapi/index.js @@ -3,7 +3,6 @@ const path = require("path") const fs = require("fs") const cds = require('@sap/cds'), { BuildTaskProvider, BuildTaskHandler } = cds.build const cdsdk = require('@sap/cds-dk') -const { path4 } = cds.serve const logger = cds.log("build") module.exports.activate = () => { @@ -18,15 +17,10 @@ module.exports.activate = () => { applyTaskDefaults(task) { task.src = task.src || cds.env.folders.srv.replace(/\/$/, '') } - async lookupTasks() { - if (process.env.NODE_ENV === 'production') { - return [{ for: this.id }] - } - } get handler() { return class extends BuildTaskHandler { async clean() { - fs.rm(path.join(this.task.dest, "gen/docs"), { recursive: true, force: true }, (err) => logger.error(err)) + fs.rm(path.join(this.task.dest, "openapi-docs"), { recursive: true, force: true }, (err) => logger.error(err)) } async build() { @@ -37,15 +31,24 @@ module.exports.activate = () => { await Promise.all(cds.linked(model).services.map(service => { const openApi = cdsdk.compile.to.openapi(model, { service: service.name, - 'openapi:url': path4(service).replace(/\.[^.]+$/, ''), 'openapi:diagram': options.diagram }) - this.write(openApi).to(`gen/docs/${service.name}.openapi3.json`) + this.write(openApi).to(`openapi-docs/${service.name}.openapi3.json`) })) } } } + /** + * Additional constraints can be defined, e.g. generate openapi service specification in production builds only. + * > cds build --production + * > cds build --for node-cf --production + */ + // async lookupTasks() { + // if (process.env.NODE_ENV === 'production') { + // return [{ for: this.id }] + // } + // } })() ) } \ No newline at end of file