[Python] How to configure openapi-generator-cli to include examples in Pydantic models

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have examples associated to my pydantic models.

    class Algorithm(BaseModel):
    id: ID = Field(examples=[1], description="ID of the algorithm")
    project_id: ID = Field(examples=[1], description="ID of the project")


    and I am using openapi-generator-cli to generate a client to the REST api. The problem is that the models that get generated only have description field in them and NOT the examples that I defined.

    class Algorithm(BaseModel):
    """
    Algorithm
    """ # noqa: E501
    id: StrictInt = Field(description="ID of the algorithm")
    project_id: StrictInt = Field(description="ID of the project")


    I am using OPENAPI_GENERATOR_VERSION=7.14.0 and openapi_version=3.1.1.

    can someone please point to a direction as to how this can be achieved ? I don't have this issue with datamodel-codegen and it correctly does so.

    Continue reading...

Compartilhe esta Página