From 4ff2f66bbd9cda4042b97b44594af0bdd9c54164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stef=20Ch=C3=A4ser?= Date: Mon, 18 Nov 2024 08:35:48 +0100 Subject: [PATCH 1/3] fix: workaround validatorjs that broke generated documenation in readme.md --- bin/apikana | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/apikana b/bin/apikana index 98b31ac..46930b7 100755 --- a/bin/apikana +++ b/bin/apikana @@ -134,16 +134,18 @@ function generate() { var generator = plop.getGenerator('start'); const model = Object.assign({}, packageJSON, { api: openapi }); - // Workaround for validatorjs to fix wildcard on `paths` - const paths = []; - Object.values(model.api.paths).forEach(path => paths.push(path)); - model.api.paths = paths; - if (defaults.validation) { - const Validator = require('validatorjs') - const validator = new Validator(model.api, defaults.validation); + + // Workaround for validatorjs to validate also 'paths' with wildcard + var openapiToValidate = JSON.parse(JSON.stringify(openapi)); + openapiToValidate.paths = Object.values(openapiToValidate.paths); + + const Validator = require('validatorjs'); + + const validator = new Validator(openapiToValidate, defaults.validation); if(!validator.check()) { - log(colors.bold(colors.red('Validation of the OpenAPI definition has failed with ' + validator.errorCount + ' errors'))); + log(colors.bold(colors.red('Validation of the OpenAPI (api.yaml) has failed with ' + validator.errorCount + ' error(s).'))); + log(colors.bold(colors.red('Validation rules your API must conform are defined in: '+path.join(defaults.dir,'index.js')))); Object.entries(validator.errors.all()).forEach(errorEntry => { const [errorField, error] = errorEntry; log(colors.bold(colors.red(errorField + ": " + error))) From 221d27aaa58d5b721e2ce746acd40daf7c6032d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stef=20K=C3=A4ser?= Date: Tue, 19 Nov 2024 08:04:15 +0100 Subject: [PATCH 2/3] chore: fix formatting --- bin/apikana | 100 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/bin/apikana b/bin/apikana index 46930b7..0c7c882 100755 --- a/bin/apikana +++ b/bin/apikana @@ -11,7 +11,7 @@ var argc = process.argv.length; require('../src/logo'); -if(!process.version.startsWith('v8') && !process.version.startsWith('v10')) { +if (!process.version.startsWith('v8') && !process.version.startsWith('v10')) { log(colors.bold(colors.red('Expected node version v8.x or v10.x but current version is ' + process.version))); process.exit(1); } @@ -25,26 +25,26 @@ if (argc === 2) { process.exit(1); } switch (process.argv[2]) { - case 'init': - require('../src/init/init'); - break; - case 'start': - generate(); - break; - case 'stop': - require('../src/server/stop').stop(params.port(), function () { - log('Stopped'); - }); - break; - case 'create-sample': - createSample(); - break; - case 'validate-samples': - validateSamples(); - break; - default: - help(); - break; + case 'init': + require('../src/init/init'); + break; + case 'start': + generate(); + break; + case 'stop': + require('../src/server/stop').stop(params.port(), function () { + log('Stopped'); + }); + break; + case 'create-sample': + createSample(); + break; + case 'validate-samples': + validateSamples(); + break; + default: + help(); + break; } } @@ -55,30 +55,30 @@ function help() { log(' source', ' Directory containing the APIs and models. Default: src'); log(colors.gray(' --api='), ' The main api file (yaml or json). Default: openapi/api.yaml'); log(colors.gray(' --models='), ' The directory containing the models, if no api file is given.\n' + - ' Default: ts'); + ' Default: ts'); log(colors.gray(' --style='), ' The directory containing css files for the swagger GUI.\n' + - ' Default: style'); + ' Default: style'); log(colors.gray(' --config='), ' Read additional options from a file in JSON format.'); log(colors.gray(' --javaPackage='), ' Java package to use.'); - log(colors.gray(' --pathPrefix='), ' The common prefix for api paths to be used in generated *Paths files.\n'+ - ' Default: none'); + log(colors.gray(' --pathPrefix='), ' The common prefix for api paths to be used in generated *Paths files.\n' + + ' Default: none'); log(colors.gray(' --basePath='), ' Override basePath specified in api file'); - log(colors.gray(' --generate1stGenPaths='),'\n' + - ' Enable/disable generator for 1st generation path constants.\n' + - ' Since: v0.5.1\n' + - ' Default: true (enabled)'); - log(colors.gray(' --generate2ndGenPaths='),'\n' + - ' Enable/disable generator for 2nd generation path constants.\n' + - ' Since: v0.5.1\n' + - ' Default: true (enabled)'); - log(colors.gray(' --generate3rdGenPaths='),'\n' + - ' Enable/disable generator for 3rd generation path constants.\n' + - ' Since: v0.5.0\n' + - ' Default: false (disabled)'); - log(colors.gray(' --deploy='), ' If the sources should be copied into the target directory. \n'+ - ' Default: false'); - log(colors.gray(' --dependencyPath='), ' Directory containing API dependencies.\n'+ - ' Default: node_modules/-api-dependencies'); + log(colors.gray(' --generate1stGenPaths='), '\n' + + ' Enable/disable generator for 1st generation path constants.\n' + + ' Since: v0.5.1\n' + + ' Default: true (enabled)'); + log(colors.gray(' --generate2ndGenPaths='), '\n' + + ' Enable/disable generator for 2nd generation path constants.\n' + + ' Since: v0.5.1\n' + + ' Default: true (enabled)'); + log(colors.gray(' --generate3rdGenPaths='), '\n' + + ' Enable/disable generator for 3rd generation path constants.\n' + + ' Since: v0.5.0\n' + + ' Default: false (disabled)'); + log(colors.gray(' --deploy='), ' If the sources should be copied into the target directory. \n' + + ' Default: false'); + log(colors.gray(' --dependencyPath='), ' Directory containing API dependencies.\n' + + ' Default: node_modules/-api-dependencies'); log(colors.gray(' --port='), ' Port to serve the HTML documentation. Default: 8333'); log(colors.gray(' --serve='), ' If the HTML documentation should be served over HTTP. Default: true'); log(colors.gray(' --openBrowser='), ' If the browser should be opened at first start. Default: true'); @@ -130,9 +130,9 @@ function generate() { }); function run(defaults) { - var plop = nodePlop(__dirname + '/../src/plopfile_start.js', { defaults }); + var plop = nodePlop(__dirname + '/../src/plopfile_start.js', {defaults}); var generator = plop.getGenerator('start'); - const model = Object.assign({}, packageJSON, { api: openapi }); + const model = Object.assign({}, packageJSON, {api: openapi}); if (defaults.validation) { @@ -143,12 +143,12 @@ function generate() { const Validator = require('validatorjs'); const validator = new Validator(openapiToValidate, defaults.validation); - if(!validator.check()) { + if (!validator.check()) { log(colors.bold(colors.red('Validation of the OpenAPI (api.yaml) has failed with ' + validator.errorCount + ' error(s).'))); - log(colors.bold(colors.red('Validation rules your API must conform are defined in: '+path.join(defaults.dir,'index.js')))); + log(colors.bold(colors.red('Validation rules your API must conform are defined in: ' + path.join(defaults.dir, 'index.js')))); Object.entries(validator.errors.all()).forEach(errorEntry => { - const [errorField, error] = errorEntry; - log(colors.bold(colors.red(errorField + ": " + error))) + const [errorField, error] = errorEntry; + log(colors.bold(colors.red(errorField + ": " + error))) }); process.exit(1); } @@ -162,7 +162,7 @@ function generate() { var defaultsVersion = packageJSON.devDependencies['apikana-defaults']; if (defaultsVersion) { - if(defaultsVersion != "0.0.0") { + if (defaultsVersion != "0.0.0") { process.stdout.write("Using defaults " + defaultsVersion + "\n"); } var defaultsDir = path.join(process.cwd(), 'node_modules', 'apikana-defaults'); @@ -172,12 +172,12 @@ function generate() { } else { process.stdout.write("Loading defaults... "); manager.install('apikana-defaults').then((e) => { - process.stdout.write("found "+e.version+"\n"); + process.stdout.write("found " + e.version + "\n"); var defaults = manager.require('apikana-defaults'); var defaultsDir = path.join(os.tmpdir(), 'apikana-plugin-packages', 'apikana-defaults'); defaults.dir = defaultsDir; var version = JSON.parse(fs.readFileSync(path.join(defaultsDir, 'package.json'))).version; - if(version != "0.0.0") { + if (version != "0.0.0") { log(colors.bold(`WARNING: | The build is unpredictable because of an implicit dependency.`)); log(colors.bold(` | It may break anytime when a new version of the dependency is available in the registry.`)); log(colors.bold(` | To fix this, freeze the dependency in your API project:`)); From d9f9d1e2e944fc52edc0583e7f56f3820addfa74 Mon Sep 17 00:00:00 2001 From: "@swisspost-devs" Date: Tue, 19 Nov 2024 08:10:53 +0000 Subject: [PATCH 3/3] chore(release): 0.11.2 [skip ci] --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 4cd3bd3..2682c43 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "apikana", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "apikana", - "version": "0.11.1", + "version": "0.11.2", "license": "Apache-2.0", "dependencies": { "ajv": "6.10.2", diff --git a/package.json b/package.json index 890f2ff..5c4bac4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apikana", - "version": "0.11.1", + "version": "0.11.2", "description": "Integrated tools for REST API design - アピ", "main": "index.js", "bin": {