You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am tring to generate JSON schema for TypedDict allowing for extra/optional arguments. With NotRequired typing I get the following error:
from typing import TypedDict
from apischema.json_schema import deserialization_schema
class MyTypedDict(TypedDict):
my_key1: Optional[int]
my_key2: NotRequired[int]
deserialization_schema(MyTypedDict)
>>> TypeError: NotRequired accepts only a single type. Got (<class 'int'>,).
Workaround with total=False seems to work but I expect additionalProperties to be True instead of False.
from typing import TypedDict, List
from apischema.json_schema import deserialization_schema
class MyTypedDict(TypedDict, total=False):
a: str
b: str
deserialization_schema(MyTypedDict)
>>> {'type': 'object', 'properties': {'a': {'type': 'string'}, 'b': {'type': 'string'}}, 'additionalProperties': False, '$schema': 'http://json-schema.org/draft/2020-12/schema#'}
I suggest the following:
Add support for PEP 728 closed class parameter as a way to enable "additionalProperties": true in JSON schema for TypedDict.
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 ...
The text was updated successfully, but these errors were encountered:
I am tring to generate JSON schema for TypedDict allowing for extra/optional arguments. With NotRequired typing I get the following error:
Workaround with
total=False
seems to work but I expectadditionalProperties
to be True instead of False.I suggest the following:
"additionalProperties": true
in JSON schema for TypedDict."additionalProperties": true
by default for TypedDict as the PEP states:The text was updated successfully, but these errors were encountered: