Replies: 2 comments
-
Hi, i have something similar. We have jsonschemas which do something like this: ...
},
"lastName": {
"type": "string",
"description": "The person's last name."
},
"age": {
"description": "Age in years which must be equal to or greater than zero.",
"type": "integer",
"minimum": 0
}
},
"allOf": [
{
"if": {
"properties": {
"lastName": { "const": "Doe" }
}
},
"then": {
"required": ["age"]
}
}
]
} Do you have something like this in mind. christian |
Beta Was this translation helpful? Give feedback.
-
I kinda want something like this as well - in my case I want to change my field annotations to use the
I'd prefer to have a generic override mechanism for this than to have special logic in datamodel-code-generator for every possible override. If OP's desire for custom validators could be done in a generic way then it could allow me to set custom annotations as well. In particular I don't to this to be controlled in my json schema, I'd rather have it controlled by parameters set at codegen time. (i.e. my schema comes from somewhere that doesn't even understand python so it feels wrong to be putting aritrary Pydantic settings in there). Perhaps something like config = {
"field_overrides": [
{("SomeModel", "some_secret"): lambda ann: Secret[ann]} # ann is a typing.Annotation
]
} no idea of the feasibility of that though :( |
Beta Was this translation helpful? Give feedback.
-
First I want to start with a big thank you to the community for creating such a great package. It's been helping us a lot.
It would be nice to be able to add custom Pydantic validators to some of the classes that require non-trivial validation logic.
This would be helpful as the model is then consumed by FastAPI, which would run these validators during de-serialization.
While I understand this is probably not currently supported (unless I missed something), I was wondering if there was some way I could customize the codegen step such that these Pydantic validators can be added directly.
Beta Was this translation helpful? Give feedback.
All reactions