fastapi-code-generator icon indicating copy to clipboard operation
fastapi-code-generator copied to clipboard

Generates incorrect pydantic Fields with example argument rather than examples

Open nigelsim opened this issue 9 months ago • 0 comments

My project has

[tool.poetry.dependencies]
python = "^3.11"
fastapi = "0.110.3"

[tool.poetry.group.dev.dependencies]
fastapi-code-generator = "^0.5.0"

which results in datamodel-code-generator 0.25.6 I'm getting models like this generated:

    api_version: Optional[str] = Field(
        None,
        description='Indication of the API version implemented at this URL.  Must be "v0.4.2" when implementing this version of the API.',
        example='v0.4.2',
    )

But Pydantic Field has no argument example. It has examples though.

Example file

This appears to be because this is an OpenAPI 3.0.2 file, and apparently in [OAI 3.1[(https://redocly.com/docs/openapi-visual-reference/schemas/#example-and-examples) example changes to examples.

components:
  schemas:
    StatusResponse:
      type: object
      required:
        - status
      properties:
        api_version:
          description: |-
            Indication of the API version implemented at this URL.  Must be "v0.4.2" when implementing this version of the API.
          type: string
          example: v0.4.2

```

nigelsim avatar May 10 '24 12:05 nigelsim