What does this contract check print?

from API-first design
OpenAPI 3.2.0 / Node 24 beginner 2 min

What does this contract check print?

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");
Open in playground
Report an error