Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading