Add support for PEP 728 – TypedDict with Typed Extra Items
Is your feature request related to a problem? Please describe.
I can't find a way to get "additionalProperties": true in JSON schema for a TypedDict.
Describe the solution you'd like I suggest the following:
- Add support for PEP 728 closed class parameter as a way to enable
"additionalProperties": truein JSON schema for TypedDict. - Set
"additionalProperties": trueby default for TypedDict as the PEP states:
Passing closed=False explicitly requests the default TypedDict behavior, where arbitrary other keys may be present ...
Describe alternatives you've considered None
Additional context
from typing_extensions import TypedDict, NotRequired
class SoftwareVersion(TypedDict, closed=False):
NAME: str
VERSION: str
BUILD: NotRequired[str]
>>> print(build_json_schema(SoftwareVersion).to_json())
{"type": "object", "properties": {"NAME": {"type": "string"}, "VERSION": {"type": "string"}, "BUILD": {"type": "string"}}, "additionalProperties": false, "required": ["NAME", "VERSION"]}
It would be a great addition to the library. However, I will make a suggestion - in addition to true/false, we can use the additional value type, because this is exactly what PEP 728 suggests with extra_items and matches the JSON Schema specification.
Would you be willing to make a PR for that?