You've already forked nginx-proxy-manager
							
							
				mirror of
				https://github.com/NginxProxyManager/nginx-proxy-manager.git
				synced 2025-11-04 04:11:42 +03:00 
			
		
		
		
	frontend doesn't include when building in react version adds swagger for existing dns-providers endpoint
		
			
				
	
	
		
			46 lines
		
	
	
		
			928 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			928 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import Ajv from "ajv/dist/2020.js";
 | 
						|
import errs from "../error.js";
 | 
						|
 | 
						|
const ajv = new Ajv({
 | 
						|
	verbose: true,
 | 
						|
	allErrors: true,
 | 
						|
	allowUnionTypes: true,
 | 
						|
	strict: false,
 | 
						|
	coerceTypes: true,
 | 
						|
});
 | 
						|
 | 
						|
/**
 | 
						|
 * @param {Object} schema
 | 
						|
 * @param {Object} payload
 | 
						|
 * @returns {Promise}
 | 
						|
 */
 | 
						|
const apiValidator = async (schema, payload /*, description*/) => {
 | 
						|
	if (!schema) {
 | 
						|
		throw new errs.ValidationError("Schema is undefined");
 | 
						|
	}
 | 
						|
 | 
						|
	// Can't use falsy check here as valid payload could be `0` or `false`
 | 
						|
	if (typeof payload === "undefined") {
 | 
						|
		throw new errs.ValidationError("Payload is undefined");
 | 
						|
	}
 | 
						|
 | 
						|
 | 
						|
	const validate = ajv.compile(schema);
 | 
						|
 | 
						|
	const valid = validate(payload);
 | 
						|
 | 
						|
 | 
						|
	if (valid && !validate.errors) {
 | 
						|
		return payload;
 | 
						|
	}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
	const message = ajv.errorsText(validate.errors);
 | 
						|
	const err = new errs.ValidationError(message);
 | 
						|
	err.debug = {validationErrors: validate.errors, payload};
 | 
						|
	throw err;
 | 
						|
};
 | 
						|
 | 
						|
export default apiValidator;
 |