Skip to content

improvement/1045: Replace deprecated example / extra field arguments with json_schema_extra (Pydantic V2 migration) #45

@babakjahan

Description

@babakjahan

Several model fields in the project still use deprecated keyword arguments such as example, examples, or extra in Field() definitions.
These were valid in Pydantic V1, but are now deprecated in Pydantic V2 and will be removed in V3.

Starting from Pydantic V2, any additional metadata such as examples must be added using the json_schema_extra dictionary instead of direct keyword arguments.

⚠️ using extra keyword arguments on Field is deprecated and will be removed.
Use json_schema_extra instead. (Extra keys: 'example').
Deprecated in Pydantic V2.0 to be removed in V3.0.

Use json_schema_extra instead:

page: int = Field(
    ...,
    ge=1,
    description="Current page number",
    json_schema_extra={"example": 1}
)

Or if you want multiple examples:

page: int = Field(
    ...,
    ge=1,
    description="Current page number",
    json_schema_extra={"examples": [1, 2, 3]}
)

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions