diff --git a/packages/cli/generators/controller/index.js b/packages/cli/generators/controller/index.js index 459257c1d731..1b94a8cd98cc 100644 --- a/packages/cli/generators/controller/index.js +++ b/packages/cli/generators/controller/index.js @@ -56,6 +56,11 @@ module.exports = class ControllerGenerator extends ArtifactGenerator { required: false, description: g.f('Type for the %s', this.artifactInfo.type), }); + this.option('outDir', { + type: String, + required: false, + description: 'Custom output directory for controller', + }); return super._setupGenerator(); } @@ -261,6 +266,9 @@ module.exports = class ControllerGenerator extends ArtifactGenerator { if (debug.enabled) { debug(`Using template at: ${source}`); } + if (this.options.outDir) { + this.artifactInfo.outDir = path.resolve(this.options.outDir); + } const dest = this.destinationPath( path.join(this.artifactInfo.outDir, this.artifactInfo.outFile), ); diff --git a/packages/cli/lib/base-generator.js b/packages/cli/lib/base-generator.js index 7828de412f2b..87deffbe88fd 100644 --- a/packages/cli/lib/base-generator.js +++ b/packages/cli/lib/base-generator.js @@ -494,20 +494,20 @@ module.exports = class BaseGenerator extends Generator { } async _updateIndexFile(dir, file) { - await updateIndex(dir, file, this.fs); - - // Output for users const updateDirRelPath = path.relative( this.artifactInfo.relPath, this.artifactInfo.outDir, ); - const outPath = path.join( + await updateIndex( this.artifactInfo.relPath, + file, + this.fs, updateDirRelPath, - 'index.ts', ); + // Output for users + const outPath = path.join(this.artifactInfo.relPath, 'index.ts'); this.log(chalk.green(' update'), `${outPath}`); } }; diff --git a/packages/cli/lib/update-index.js b/packages/cli/lib/update-index.js index 632914ea4404..41161c57642f 100644 --- a/packages/cli/lib/update-index.js +++ b/packages/cli/lib/update-index.js @@ -19,7 +19,7 @@ const defaultFs = { * @param {String} dir The directory in which index.ts is to be updated/created * @param {*} file The new file to be exported from index.ts */ -module.exports = async function (dir, file, fsApis) { +module.exports = async function (dir, file, fsApis, subDir = '') { const {read, write, append, exists} = {...defaultFs, ...fsApis}; debug(`Updating index with ${path.join(dir, file)}`); const indexFile = path.join(dir, 'index.ts'); @@ -32,7 +32,7 @@ module.exports = async function (dir, file, fsApis) { if (indexExists) { index = await read(indexFile); } - const content = `export * from './${file.slice(0, -3)}';\n`; + const content = `export * from './${subDir ? subDir + '/' : ''}${file.slice(0, -3)}';\n`; if (!index.includes(content)) { if (indexExists) { await append(indexFile, content); diff --git a/packages/rest/src/validation/request-body.validator.ts b/packages/rest/src/validation/request-body.validator.ts index ffdb16888f84..f55b9cf085d6 100644 --- a/packages/rest/src/validation/request-body.validator.ts +++ b/packages/rest/src/validation/request-body.validator.ts @@ -184,7 +184,6 @@ export async function validateValueAgainstSchema( buildErrorDetails(validationErrors), ); } - // Throw invalid value error throw RestHttpErrors.invalidData(value, options.name ?? '(unknown)', { details: buildErrorDetails(validationErrors),