Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function initializeZSchema () {
// HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
delete openapi.v2.id;
delete openapi.v3.id;
// The OpenAPI 3.0 schema uses "uri-reference" formats.
// Assume that any non-whitespace string is valid.
ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);
// Configure ZSchema
return new ZSchema({
breakOnFirstError: true,
noExtraKeywords: true,
ignoreUnknownFormats: false,
reportPathAsArray: true
});
}
function validateSchema (api) {
// Choose the appropriate schema (Swagger or OpenAPI)
let schema = api.swagger ? openapi.v2 : openapi.v3;
// Validate against the schema
let isValid = zSchema.validate(api, schema);
if (!isValid) {
let err = zSchema.getLastError();
let message = "Swagger schema validation failed. \n" + formatZSchemaError(err.details);
throw ono.syntax(err, { details: err.details }, message);
}
}
function initializeZSchema () {
// HACK: Delete the OpenAPI schema IDs because ZSchema can't resolve them
delete openapi.v2.id;
delete openapi.v3.id;
// The OpenAPI 3.0 schema uses "uri-reference" formats.
// Assume that any non-whitespace string is valid.
ZSchema.registerFormat("uri-reference", (value) => value.trim().length > 0);
// Configure ZSchema
return new ZSchema({
breakOnFirstError: true,
noExtraKeywords: true,
ignoreUnknownFormats: false,
reportPathAsArray: true
});
}