Openapi Schema improvements

- Return proper booleans in api responses
- Update jsonschemavalidation to latest draft
This commit is contained in:
Jamie Curnow
2024-10-10 15:53:11 +10:00
parent dfe2588523
commit 4572b205c9
69 changed files with 862 additions and 2082 deletions

View File

@ -1,11 +1,12 @@
const Ajv = require('ajv/dist/2020');
const error = require('../error');
const ajv = require('ajv')({
verbose: true,
validateSchema: true,
allErrors: false,
format: 'full',
coerceTypes: true
const ajv = new Ajv({
verbose: true,
allErrors: true,
allowUnionTypes: true,
strict: false,
coerceTypes: true,
});
/**
@ -25,8 +26,8 @@ function apiValidator (schema, payload/*, description*/) {
return;
}
let validate = ajv.compile(schema);
let valid = validate(payload);
const validate = ajv.compile(schema);
const valid = validate(payload);
if (valid && !validate.errors) {
resolve(payload);

View File

@ -1,15 +1,17 @@
const _ = require('lodash');
const Ajv = require('ajv/dist/2020');
const error = require('../error');
const commonDefinitions = require('../../schema/common.json');
RegExp.prototype.toJSON = RegExp.prototype.toString;
const ajv = require('ajv')({
verbose: true,
allErrors: true,
format: 'full', // strict regexes for format checks
coerceTypes: true,
schemas: [commonDefinitions]
const ajv = new Ajv({
verbose: true,
allErrors: true,
allowUnionTypes: true,
coerceTypes: true,
strict: false,
schemas: [commonDefinitions]
});
/**
@ -38,7 +40,6 @@ function validator (schema, payload) {
}
}
});
}
module.exports = validator;