Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generates incorrect pydantic Fields with example argument rather than examples #415

Open
nigelsim opened this issue May 10, 2024 · 0 comments

Comments

@nigelsim
Copy link

nigelsim commented May 10, 2024

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

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant