Skip to content

Commit

Permalink
JSON schema: fix extra parameter handling
Browse files Browse the repository at this point in the history
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 #7809.
  • Loading branch information
me-and committed Oct 12, 2023
1 parent 9e35825 commit 79b130e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pydantic/json_schema.py
Expand Up @@ -1195,7 +1195,10 @@ def typed_dict_schema(self, schema: core_schema.TypedDictSchema) -> JsonSchemaVa
with self._config_wrapper_stack.push(config):
json_schema = self._named_required_fields_schema(named_required_fields)

extra = config.get('extra', 'ignore')
try:
extra = schema['extra_behavior']
except KeyError:
extra = config.get('extra', 'ignore')
if extra == 'forbid':
json_schema['additionalProperties'] = False
elif extra == 'allow':
Expand Down

0 comments on commit 79b130e

Please sign in to comment.