Skip to content

Add support for PEP 728 – TypedDict with Typed Extra Items #271

Open
@tokarenko

Description

@tokarenko

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:

  1. Add support for PEP 728 closed class parameter as a way to enable "additionalProperties": true in JSON schema for TypedDict.
  2. Set "additionalProperties": true by 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"]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions