However, in Pydantic V2, this is now called examples¹² and is a list of examples. The Scanner snippet above should be changed to the following:
class Scanner(BaseModel):
name: Optional[str] = Field(
None, description="Name of the scanner", examples=["Trivy"]
)
vendor: Optional[str] = Field(
None, description="Name of the scanner provider", examples=["Aqua Security"]
)
version: Optional[str] = Field(
None, description="Version of the scanner adapter", examples=["v0.9.1"]
)
If this isn't fixed in datamodel-code-generator soon, we either have to try to contribute the fix ourselves, or we have to perform some AST manipulation to rewrite all instances of example.
datamodel-code-generator
generatespydantic.Field
attributes with the kwargexample
which contains a single example value for the field:https://github.com/pederhan/harborapi/blob/705903fabc44c2e381bab55a75e1847a77032b98/harborapi/models/_models.py#L182-L191
However, in Pydantic V2, this is now called
examples
¹ ² and is a list of examples. TheScanner
snippet above should be changed to the following:If this isn't fixed in datamodel-code-generator soon, we either have to try to contribute the fix ourselves, or we have to perform some AST manipulation to rewrite all instances of
example
.1: https://docs.pydantic.dev/latest/api/fields/#pydantic.fields.Field 2: https://docs.pydantic.dev/latest/concepts/fields/#customizing-json-schema