-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
Description
I found a weird inconsistency when generating JSON schema:
Variant 1
import msgspec
from typing import Annotated
import json
key_type = Annotated[str, msgspec.Meta(pattern=r'^A$')]
value_type = Annotated[str, msgspec.Meta(pattern=r'^B$')]
dict_type = Annotated[dict[key_type, value_type], msgspec.Meta(min_length=1)]
schema = msgspec.json.schema(dict_type)
print(json.dumps(schema, indent=2))
results in:
{
"type": "object",
"propertyNames": {
"pattern": "^A$"
},
"additionalProperties": {
"type": "string",
"pattern": "^B$"
},
"minProperties": 1
}
✔️ works as expected
Variant 2
import msgspec
from typing import Annotated
import json
key_type = Annotated[str, msgspec.Meta(title='key', pattern=r'^A$')]
value_type = Annotated[str, msgspec.Meta(pattern=r'^B$')]
dict_type = Annotated[dict[key_type, value_type], msgspec.Meta(min_length=1)]
schema = msgspec.json.schema(dict_type)
print(json.dumps(schema, indent=2))
results in:
{
"type": "object",
"additionalProperties": {
"type": "string",
"pattern": "^B$"
},
"minProperties": 1
}
❌ Merely adding the title
kwarg to key_type
results in the propertyNames
section being dropped entirely.
Metadata
Metadata
Assignees
Labels
No labels