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
Is your feature request related to a problem? Please describe.
I wrote a valid JSON Schema with many properties
Some properties' pattern make use of look-ahead and look-behind, which are supported by JSON Schema specifications.
See: JSON Schema supported patterns
datamodel-code-generator generated the PydanticV2 models.
Describe the solution you'd like
PydanticV2 supports look-around, look-ahead and look-behind using Python as regex engine: pydantic/pydantic#7058 (comment)
I'd like to have a configuration parameter to use python-re as regex engine for Pydantic V2.
Describe alternatives you've considered
Workaround:
[tool.datamodel-codegen]# Optionsinput = "<project>/data/schemas/"input-file-type = "jsonschema"output = "<project>/models/"output-model-type = "pydantic_v2.BaseModel"# Typing customizationbase-class = "<project>.models._base_model._BaseModel"enum-field-as-literal = "all"use-annotated = true
use-standard-collections = true
use-union-operator = true
# Field customizationcollapse-root-models = true
snake-case-field = true
use-field-description = true
# Model customizationdisable-timestamp = true
enable-faux-immutability = true
target-python-version = "3.12"use-schema-description = true
# OpenAPI-only options## We may not want to use these options as we are not generating from OpenAPI schemas# but this is a workaround to avoid `type | None` in when we have a default value.## The author of the tool doesn't know why he flagged this option as OpenAPI only.# Reference: https://github.com/koxudaxi/datamodel-code-generator/issues/1441strict-nullable = true
The text was updated successfully, but these errors were encountered:
datamodel-code-genertor should automatically add ConfigDict(regex_engine='python-re') for you when it sees a field called pattern that is using look-around, look-ahead or look-behind regex.
Are you using collapse_root_models=True? Because I am using this and I see that ConfigDict(regex_engine='python-re') is not added to BaseModel that have merged fields from a RootModel where the RootModel had ConfigDict(regex_engine='python-re'). So I am curious if this also the same use case for you, and if so then it may be a bug.
Yeah then I think it is a bug. Ideally I think when using collapse_root_models=True the ConfigDict from the RootModel should be merged with the ConfigDict in the parent BaseModel.
Is your feature request related to a problem? Please describe.
See: JSON Schema supported patterns
datamodel-code-generator
generated the PydanticV2 models.Describe the solution you'd like
PydanticV2 supports look-around, look-ahead and look-behind using Python as regex engine: pydantic/pydantic#7058 (comment)
I'd like to have a configuration parameter to use
python-re
as regex engine for Pydantic V2.Describe alternatives you've considered
Workaround:
datamodel-codegen --base-model "module.with.basemodel._BaseModel"
EDIT:
Configuration used:
The text was updated successfully, but these errors were encountered: