Describe the bug
When converting patternProperties for object to pydantic v2 models, the key constraints only show up when not using --use-annotated.
To Reproduce
Example schema:
{
"type": "object",
"patternProperties": {
"^pattern.*$": {
"type": "string"
}
},
"additionalProperties": false
}
Used commandline:
$ uvx --from datamodel-code-generator datamodel-codegen --input schema.json --input-file-type jsonschema --output models.py --output-model-type pydantic_v2.BaseModel --use-annotated --formatters ruff-format ruff-check
Expected behavior
Key should be annotated with pattern.
dict[Annotated[str, Field(pattern="^pattern.*$")], str]
instead of: dict[str, str].
Version:
- OS: Linux
- Python version: 3.13
- datamodel-code-generator version: 0.53.0
Additional context
Without --use-annotated, it does preserve the pattern as dict[constr(pattern=r"^pattern.*$"), str].
Describe the bug
When converting
patternPropertiesfor object to pydantic v2 models, the key constraints only show up when not using--use-annotated.To Reproduce
Example schema:
{ "type": "object", "patternProperties": { "^pattern.*$": { "type": "string" } }, "additionalProperties": false }Used commandline:
Expected behavior
Key should be annotated with pattern.
instead of:
dict[str, str].Version:
Additional context
Without
--use-annotated, it does preserve the pattern asdict[constr(pattern=r"^pattern.*$"), str].