ephelan-spectral-ruleset
Version:
58 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const expectedSchema = {
type: 'object',
properties: {
kind: {
type: 'string'
},
page: {
type: 'integer'
},
size: {
type: 'integer'
},
total: {
type: 'integer'
}
}
};
exports.default = (targetVal, _, paths) => {
if (!targetVal.schemas) {
return [
{
message: 'OpenAPI object `components` should contain a `schemas` object.'
}
];
}
if (!targetVal.schemas.ObjectReference) {
return [
{
message: 'OpenAPI object `components.schemas` should contain a `ObjectReference` object'
}
];
}
const results = [];
const rootPath = paths.target !== void 0 ? paths.target : paths.given;
if ((expectedSchema === null || expectedSchema === void 0 ? void 0 : expectedSchema.type) != (targetVal === null || targetVal === void 0 ? void 0 : targetVal.type)) {
results.push({
message: `"type" should be "${expectedSchema.type}"`,
path: [...rootPath, 'type']
});
}
if (typeof (targetVal === null || targetVal === void 0 ? void 0 : targetVal.properties) != 'object') {
results.push({
message: `"properties" should be an object type`,
path: [...rootPath, 'properties']
});
}
const properties = targetVal.properties;
if ((properties === null || properties === void 0 ? void 0 : properties.type) != (targetVal === null || targetVal === void 0 ? void 0 : targetVal.type)) {
results.push({
message: `"type" should be "${expectedSchema.type}"`,
path: [...rootPath, 'type']
});
}
return results;
};
//# sourceMappingURL=objectReferenceSchema.js.map