@svengroup/openapi-to-pdf
Version:
Create PDF API reference documentation from OpenAPI 3.0.x specification files.
23 lines (22 loc) • 837 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = validate;
const accepted_versions = ["3.0"]; // accepted versions
async function validate(oas) {
const { Validator } = await import("@seriousme/openapi-schema-validator");
const validator = new Validator();
const res = await validator.validate(oas);
if (res.valid) {
const version = validator.version;
if (!accepted_versions.includes(version)) {
throw `Found OpenAPI v${version} but accepted versions are only: ${accepted_versions.join(', ')}`;
}
const schema = validator.resolveRefs();
/** @ts-expect-error using type from different package */
return schema;
}
else {
console.error(res.errors);
throw "OpenAPI Schema is not valid.";
}
}