mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 10:06:26 +00:00
Refactor API Schema and validation
- /schema now returns full openapi/swagger schema - That schema is used to validate incoming requests - And used as a contract in future integration tests - Moved route files up one level - Fixed incorrect 404 reponses when getting objects - Fixed saving new objects and passing jsonschemavalidation
This commit is contained in:
@ -1,6 +1,4 @@
|
||||
const error = require('../error');
|
||||
const path = require('path');
|
||||
const parser = require('json-schema-ref-parser');
|
||||
const error = require('../error');
|
||||
|
||||
const ajv = require('ajv')({
|
||||
verbose: true,
|
||||
@ -17,8 +15,14 @@ const ajv = require('ajv')({
|
||||
*/
|
||||
function apiValidator (schema, payload/*, description*/) {
|
||||
return new Promise(function Promise_apiValidator (resolve, reject) {
|
||||
if (schema === null) {
|
||||
reject(new error.ValidationError('Schema is undefined'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof payload === 'undefined') {
|
||||
reject(new error.ValidationError('Payload is undefined'));
|
||||
return;
|
||||
}
|
||||
|
||||
let validate = ajv.compile(schema);
|
||||
@ -35,11 +39,4 @@ function apiValidator (schema, payload/*, description*/) {
|
||||
});
|
||||
}
|
||||
|
||||
apiValidator.loadSchemas = parser
|
||||
.dereference(path.resolve('schema/index.json'))
|
||||
.then((schema) => {
|
||||
ajv.addSchema(schema);
|
||||
return schema;
|
||||
});
|
||||
|
||||
module.exports = apiValidator;
|
||||
|
Reference in New Issue
Block a user