@rhoas/spectral-ruleset
Version:
37 lines • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (targetVal, opts, context) => {
if (!targetVal) {
return [
{
message: '"servers" should be defined',
},
];
}
if (!Array.isArray(targetVal)) {
return [
{
message: '"servers" config should be an array, got object'
}
];
}
const paths = context.path;
const results = [];
const expectedUrls = opts.required;
const missingUrls = [];
for (const u of expectedUrls) {
if (!targetVal.find(c => c.url === u)) {
missingUrls.push(u);
}
}
if (missingUrls.length) {
return [
{
message: `OpenAPI \`servers\` object is missing the following required URLs: ${missingUrls.join(', ')}`,
path: [...paths, 0]
}
];
}
return results;
};
//# sourceMappingURL=expectServersConfig.js.map