这段契约检查会输出什么?

来自 API 优先设计
OpenAPI 3.2.0 / Node 24 入门 2分钟

这段契约检查会输出什么?

JavaScript
const contract = {
  status: 201,
  requiredHeaders: ["Location"],
};

const response = {
  status: 201,
  headers: { "Content-Type": "application/json" },
};

const errors = [];
if (response.status !== contract.status) errors.push("wrong status");
for (const name of contract.requiredHeaders) {
  if (!(name in response.headers)) errors.push(`missing ${name}`);
}
console.log(errors.join(", ") || "OK");
在试验场中打开
报告错误