Skip to content

Fix: ignore undefined values in schema properties#2582

Open
veeceey wants to merge 2 commits intoajv-validator:masterfrom
veeceey:fix/issue-2578-undefined-schema-values
Open

Fix: ignore undefined values in schema properties#2582
veeceey wants to merge 2 commits intoajv-validator:masterfrom
veeceey:fix/issue-2578-undefined-schema-values

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

Summary

This PR fixes issue #2578 where schemas with undefined property values (commonly from destructuring) cause ajv to throw a TypeError instead of ignoring them.

Before:

const ajv = new Ajv({strictSchema: false, validateSchema: false});
const schema = {
  type: 'object',
  properties: {
    foo: {type: 'string'},
    bar: undefined  // From destructuring or conditional logic
  }
};
ajv.validate(schema, {foo: 'test'}); // Throws: "Cannot convert undefined or null to object"

After:

ajv.validate(schema, {foo: 'test'}); // Returns: true (undefined properties ignored)

Changes

  • Modified allSchemaProperties() in lib/vocabularies/code.ts to filter out undefined values
  • Added comprehensive test coverage for various scenarios with undefined schema properties

Test Coverage

The fix includes tests for:

  • Basic undefined property handling
  • Multiple undefined properties
  • Validation still works correctly for defined properties
  • Undefined values from destructuring scenarios

Manual Testing

Verified the fix handles:

  • Single undefined properties
  • Multiple undefined properties mixed with valid ones
  • Validation errors still work correctly for defined properties
  • Pattern properties with undefined values

Closes #2578

@veeceey veeceey force-pushed the fix/issue-2578-undefined-schema-values branch from da81290 to 46c435e Compare February 15, 2026 07:06
@veeceey
Copy link
Author

veeceey commented Mar 10, 2026

gentle ping — would be great to get some eyes on this when possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

undefined values in schemas are not ignored but throws TypeError

1 participant