Is your feature request related to a problem? Please describe.
I would like to be able to define Pydantic v2 ClassVars using JSON Schema.
Describe the solution you'd like
After some investigation, I think the cleanest approach is to use a JSON Schema extra property with an x- prefix.
Proposed Schema
{
"type": "object",
"properties": {
"namespace": {
"type": "string",
"x-is_classvar": true,
"default": "test"
}
}
}
Is generating a class variable:
class Model(BaseModel):
namespace: ClassVar[str | None] = 'test'
Describe alternatives you've considered
Another option is to add a new command parameter, but it would be nice to have it inside the schema.
Additional context
I am happy to discuss and create a PR
Is your feature request related to a problem? Please describe.
I would like to be able to define Pydantic v2 ClassVars using JSON Schema.
Describe the solution you'd like
After some investigation, I think the cleanest approach is to use a JSON Schema extra property with an
x-prefix.Proposed Schema
Is generating a class variable:
Describe alternatives you've considered
Another option is to add a new command parameter, but it would be nice to have it inside the schema.
Additional context
I am happy to discuss and create a PR