mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-09-14 19:02:35 +00:00
Convert backend to ESM
- About 5 years overdue - Remove eslint, use bomejs instead
This commit is contained in:
@@ -1,41 +1,46 @@
|
||||
const refParser = require('@apidevtools/json-schema-ref-parser');
|
||||
import { dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import $RefParser from "@apidevtools/json-schema-ref-parser";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
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;
|
||||
/**
|
||||
* Compiles the schema, by dereferencing it, only once
|
||||
* and returns the memory cached value
|
||||
*/
|
||||
const 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
|
||||
*/
|
||||
const 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;
|
||||
};
|
||||
|
||||
export { getCompiledSchema, getValidationSchema };
|
||||
|
Reference in New Issue
Block a user