JSON schema: fix extra parameter handling #7810
Conversation
|
Hmm. The naive fix here seems to be broken by there being a field in ConfigDict that means the same thing but is currently called |
The core schema for typed dicts has an "extra_behavior" key for checking whether additional unspecified keys are allowed, but the JSON schema generator ignores this and only checks the configuration dict. Have the JSON schema generator check both places, and prefer the value set in the core schema over the one in the config dictionary if both are present. Fixes pydantic#7809.
e144602 to
79b130e
Compare
|
Okay, I think that's good. Please review! I've not managed to contrive a scenario where both the config value and the schema value are set, so that isn't included in the new tests, but the tests do cover checking |
sydney-runkle
left a comment
There was a problem hiding this comment.
LGTM at a first glance. @me-and, thanks so much for your contribution 🌟.
@davidhewitt, could you give this a review as well?
|
The tests look good. Could you simplify the 3 tests you added a bit by using |
|
Please update |
davidhewitt
left a comment
There was a problem hiding this comment.
Overall looks good to me, just one performance suggestion!
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Looks fine for now. I see you modeled this after other tests that were already present. |
sydney-runkle
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution 🥳
|
Ah, fantastic, got to it before I managed to. Thank you @sydney-runkle! |
|
Sure thing, thanks for the help! 😄 |
Change Summary
The core schema for typed dicts uses the "extra_behavior" key to determine whether additional unspecified keys are allowed in the dict; update the JSON schema generation to expect that, rather than to look for the non-existent "extra" key.
Related issue number
Fixes #7809.
Checklist
Selected Reviewer: @davidhewitt