openapi-diff
Version:
A CLI tool to identify differences between Swagger/OpenAPI specs.
25 lines (24 loc) • 853 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpecDeserialiser = void 0;
const yaml = require("js-yaml");
const open_api_diff_error_impl_1 = require("../../common/open-api-diff-error-impl");
class SpecDeserialiser {
static load(specOption) {
return SpecDeserialiser.parseSpec(specOption.location, specOption.content);
}
static parseSpec(location, content) {
try {
return JSON.parse(content);
}
catch (parseJsonError) {
try {
return yaml.load(content);
}
catch (error) {
throw new open_api_diff_error_impl_1.OpenApiDiffErrorImpl('OPENAPI_DIFF_PARSE_ERROR', `Unable to parse "${location}" as a JSON or YAML file`);
}
}
}
}
exports.SpecDeserialiser = SpecDeserialiser;