From bebee112139a2a0227bce44e655f24e57739fb24 Mon Sep 17 00:00:00 2001 From: aayushRedHat Date: Thu, 14 Dec 2023 20:15:36 +0530 Subject: [PATCH] Resolve sonar code issue --- lib/generator.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 05ff5643ff..8d6403eb38 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -101,12 +101,12 @@ class Generator { if (invalidOptions.length) throw new Error(`These options are not supported by the generator: ${invalidOptions.join(', ')}`); if (options && options.registry) { const invalidRegOptions = getInvalidOptions(REGISTRY_OPTIONS, options.registry || []); - if (invalidRegOptions.length) throw new Error(`These options are not supported by the generator to configure private registry: ${invalidRegOptions.join(', ')}`); + invalidRegOptions(invalidOptions) } if (!templateName) throw new Error('No template name has been specified.'); if (!entrypoint && !targetDir) throw new Error('No target directory has been specified.'); if (!['fs', 'string'].includes(output)) throw new Error(`Invalid output type ${output}. Valid values are 'fs' and 'string'.`); - + this.hooks = {}; /** @type {Object} Maps schema URL to folder. */ this.mapBaseUrlToFolder = mapBaseUrlToFolder; @@ -156,6 +156,18 @@ class Generator { }); }); } + + /** + * Check if the Registery Options are valid or not. + * + * @private + * @param {Object} invalidRegOptions Invalid Registery Options. + * @return {boolean} + */ + + isInvalidRegOptions(invalidRegOptions){ + if (invalidRegOptions.length) throw new Error(`These options are not supported by the generator to configure private registry: ${invalidRegOptions.join(', ')}`); + } /** * Generates files from a given template and an AsyncAPIDocument object.