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

"required" JSON keys are validated against "additionalProperties" if they are missing from "properties" #1029

Merged

Conversation

hudson-ai
Copy link
Collaborator

Rather than raising an exception when required properties don't have a schema in properties, validate against additionalProperties (consistent with Draft202012)

Somewhat arbitrarily set key order of resulting objects to:

  1. properties in order
  2. required properties mising from properties in order
  3. any other additionalProperties


if additional_properties is not False:
if additional_properties is True:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a functional change -- this line is just no longer needed since _gen_json can take bool schemas just fine

# "required" keys will be validated against "properties" if they're present, otherwise against "additionalProperties".
# If "additionalProperties" is False, then required keys must be in "properties".
if any(k not in properties for k in required) and additional_properties is False:
raise ValueError(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary, as generating with a False schema will raise an exception later. But this lets us give a more transparent error.

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.47%. Comparing base (edd8b87) to head (2de9148).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
- Coverage   70.16%   61.47%   -8.69%     
==========================================
  Files          62       62              
  Lines        4471     4470       -1     
==========================================
- Hits         3137     2748     -389     
- Misses       1334     1722     +388     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hudson-ai hudson-ai merged commit af63e6d into guidance-ai:main Sep 18, 2024
100 checks passed
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.

3 participants