Skip to content

Commit

Permalink
fix: workaround validatorjs that broke generated documenation in read…
Browse files Browse the repository at this point in the history
…me.md
  • Loading branch information
steffstefferson authored and Stef Käser committed Nov 18, 2024
1 parent cf62581 commit 3219c2c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bin/apikana
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 3219c2c

Please sign in to comment.