mirror of
				https://github.com/NginxProxyManager/nginx-proxy-manager.git
				synced 2025-11-04 09:25:15 +00:00 
			
		
		
		
	- /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
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const refParser = require('@apidevtools/json-schema-ref-parser');
 | 
						|
 | 
						|
let compiledSchema = null;
 | 
						|
 | 
						|
module.exports = {
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Compiles the schema, by dereferencing it, only once
 | 
						|
	 * and returns the memory cached value
 | 
						|
	 */
 | 
						|
	getCompiledSchema: async () => {
 | 
						|
		if (compiledSchema === null) {
 | 
						|
			compiledSchema = await refParser.dereference(__dirname + '/swagger.json', {
 | 
						|
				mutateInputSchema: false,
 | 
						|
			});
 | 
						|
		}
 | 
						|
		return compiledSchema;
 | 
						|
	},
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Scans the schema for the validation schema for the given path and method
 | 
						|
	 * and returns it.
 | 
						|
	 *
 | 
						|
	 * @param {string} path
 | 
						|
	 * @param {string} method
 | 
						|
	 * @returns string|null
 | 
						|
	 */
 | 
						|
	getValidationSchema: (path, method) => {
 | 
						|
		if (compiledSchema !== null &&
 | 
						|
			typeof compiledSchema.paths[path] !== 'undefined' &&
 | 
						|
			typeof compiledSchema.paths[path][method] !== 'undefined' &&
 | 
						|
			typeof compiledSchema.paths[path][method].requestBody !== 'undefined' &&
 | 
						|
			typeof compiledSchema.paths[path][method].requestBody.content !== 'undefined' &&
 | 
						|
			typeof compiledSchema.paths[path][method].requestBody.content['application/json'] !== 'undefined' &&
 | 
						|
			typeof compiledSchema.paths[path][method].requestBody.content['application/json'].schema !== 'undefined'
 | 
						|
		) {
 | 
						|
			return compiledSchema.paths[path][method].requestBody.content['application/json'].schema;
 | 
						|
		}
 | 
						|
		return null;
 | 
						|
	}
 | 
						|
};
 |