Your schema test failed. Now what? The error message is a wall of text. Let me teach you how to read these errors like a debugger. Every error follows a pattern — once you see it, you can fix it in seconds.
// Ajv Error:
[
{
"keyword": "required",
"dataPath": "",
"message": "should have required property 'email'",
"params": { "missingProperty": "email" }
}
]
// What happened: The response does not have the "email" field.
// Fix: Check if the API changed. If email is now optional, remove it from "required".
// If the API should have it, that is a bug — report it.// Ajv Error:
[
{
"keyword": "type",
"dataPath": ".price",
"message": "should be number",
"schemaPath": "#/properties/price/type",
"params": { "type": "number" }
}
]
// What happened: "price" is a string ("99.99") instead of a number (99.99).
// Fix: Either the API changed the type (bug) or your schema is wrong.
// Check the API docs and recent commits.// Ajv Error:
[
{
"keyword": "additionalProperties",
"dataPath": "",
"message": "should NOT have additional properties",
"params": { "additionalProperty": "createdAt" }
}
]
// What happened: API returned a "createdAt" field that is not in your schema.
// Fix: If it is an intentional new field — add it to your schema.
// If it is accidental (like exposing internal data) — report the bug.// Ajv Error:
[
{
"keyword": "pattern",
"dataPath": ".phone",
"message": "should match pattern \"^[6-9][0-9]{9}$\"",
"params": { "pattern": "^[6-9][0-9]{9}$" }
}
]
// What happened: Phone value does not match the regex. Maybe it has "+91" prefix or dashes.
// Fix: Check the actual value. Update pattern if the API format changed legitimately.// Ajv Error:
[
{
"keyword": "type",
"dataPath": ".middleName",
"message": "should be string",
"params": { "type": "string" }
}
]
// What happened: "middleName" is null, but schema only allows "string".
// Fix: If null is valid, change type to ["string", "null"].
// If null should not happen, report the API bug.Read the error message — what keyword failed? (required, type, pattern, enum, additionalProperties)
Check the dataPath — which field caused the failure?
Look at the actual API response — what value did it return?
Compare with the schema — what was expected?
Determine: is this an API bug or a schema that needs updating?
If API bug — report it with the schema error as evidence
If schema outdated — update the schema and commit the change
| Error Keyword | Meaning | Most Common Cause |
|---|---|---|
| required | A required field is missing | API removed or renamed a field |
| type | Field has wrong data type | Backend refactor changed type (string ↔ number) |
| additionalProperties | Unexpected field in response | New field added without updating schema |
| pattern | String does not match regex | Format changed (added prefix, changed separator) |
| enum | Value not in allowed list | New enum value added to API |
| minimum/maximum | Number out of range | Business logic change or data corruption |
| minItems | Array has fewer items than expected | API returned empty array unexpectedly |
Always log the actual API response alongside the schema error in your CI/CD. The error tells you what was expected. The response tells you what was received. You need BOTH to debug quickly. Add console.log(JSON.stringify(response, null, 2)) before your validation assertion.
Q: A schema validation test that was passing suddenly starts failing. How do you debug it?
A: First, I read the error message to identify which keyword failed (required, type, pattern, etc.) and which field (dataPath). Then I compare the actual API response with the schema to see the mismatch. Next, I check: was the API intentionally changed (feature release, migration) or is this a regression? I look at recent commits and deployment logs. If the change is intentional, I update the schema and commit it. If it is a regression, I report the bug with the schema error as evidence. I also check if the test environment is healthy — sometimes staging data gets corrupted.
Key Point: Read schema errors methodically: check the keyword (what failed), dataPath (which field), then compare actual response vs schema. Decide if it is an API bug or schema update.