Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: stop AdditionalPropertiesKeyword from throwing incorrect errors #148 #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BasilLangevin
Copy link

This commit prevents Opis\JsonSchema\Keywords\AdditionalPropertiesKeyword from throwing incorrect errors when the data is invalid.

To prevent erroneous invalidation, it checks the properties that have been defined in the current schema and removes them from the unchecked properties array.

This commit resolves #148

@sorinsarca
Copy link
Member

This is a quick fix but it doesn't handle patternProperties.
I whould not add logic for patternProperties inside additionalProperties keyword,
the logic must be inside patternProperties and properties; so in the end additionalProperties remains unchanged.
It is a little tricky, but it can be done.

@BasilLangevin
Copy link
Author

BasilLangevin commented Feb 11, 2025

Thank you for the guidance.

I checked out both files (PatternPropertiesKeyword and PropertiesKeyword), and the issue appears to be that PropertiesKeyword had an early return before $context->addCheckedProperties(...) when it encountered an error.

After moving addCheckedProperties up before the early return, the test suite continues to pass, and the issue with #148 is resolved.

I haven't been able to reproduce this issue using "patternProperties" - properties defined with a pattern don't seem to be incorrectly invalidated by the AdditionalPropertiesKeyword either before or after this latest fix. As such, I haven't modified the PatternPropertiesKeyword file. However, that file's validate method also returns early upon encountering an error (without first adding the checked properties context), so if there is an error with "patternProperties" validation, the solution may be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AdditionalPropertiesKeyword error incorrectly thrown
2 participants