in packages/rulesets/src/spectral/functions/patch-content-type.ts [4:38]
function checkOperationConsumes(targetVal:any) {
const { paths } = targetVal;
const errors : any[] = [];
if (paths && typeof paths === 'object') {
Object.keys(paths).forEach((path) => {
['post', 'put'].forEach((method) => {
if (paths[path][method]) {
const { consumes } = paths[path][method];
if (consumes?.includes(MERGE_PATCH)) {
errors.push({
message: `A ${method} operation should not consume 'application/merge-patch+json' content type.`,
path: ['paths', path, method, 'consumes'],
});
}
}
});
if (paths[path].patch) {
const { consumes } = paths[path].patch;
if (!consumes || !consumes.includes(MERGE_PATCH)) {
errors.push({
message: "A patch operation should consume 'application/merge-patch+json' content type.",
path: ['paths', path, 'patch', ...(consumes ? ['consumes'] : [])],
});
} else if (consumes.length > 1) {
errors.push({
message: "A patch operation should only consume 'application/merge-patch+json' content type.",
path: ['paths', path, 'patch', 'consumes'],
});
}
}
});
}
return errors;
}