@mintlify/validation
Version:
Validates mint.json files
39 lines (38 loc) • 1.38 kB
JavaScript
export const generateMessage = (path, ...messages) => {
const pathString = path
.map((component) => component.replace('\\', '\\\\').replace('/', '\\/'))
.join('/');
return [pathString, ...messages].join('\n');
};
/**
* Thrown when a value is incorrect or missing, according to the OpenAPI spec.
*/
export class InvalidSchemaError extends Error {
constructor(path, ...messages) {
super(generateMessage(path, ...messages));
this.name = 'InvalidSchemaError';
Object.setPrototypeOf(this, InvalidSchemaError.prototype);
}
}
/**
* Thrown when a schema is valid according to OpenAPI, but is unsatisfiable
* (e.g. a value that must be both a number and a string).
*/
export class ImpossibleSchemaError extends Error {
constructor(path, ...messages) {
super(generateMessage(path, ...messages));
this.name = 'ImpossibleSchemaError';
Object.setPrototypeOf(this, ImpossibleSchemaError.prototype);
}
}
/**
* Thrown when there is an issue that was caused in another part of the conversion
* (e.g. a schema in reduced form that is missing `oneOf`).
*/
export class ConversionError extends Error {
constructor(path, ...messages) {
super(generateMessage(path, ...messages));
this.name = 'ConversionError';
Object.setPrototypeOf(this, ConversionError.prototype);
}
}