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

Fix model fields with example= kwargs #39

Open
pederhan opened this issue Apr 4, 2023 · 0 comments
Open

Fix model fields with example= kwargs #39

pederhan opened this issue Apr 4, 2023 · 0 comments
Labels
API Spec Errors or inconsistencies in the API spec bug Something isn't working documentation Improvements or additions to documentation waiting Waiting for 3rd party
Milestone

Comments

@pederhan
Copy link
Member

pederhan commented Apr 4, 2023

datamodel-code-generator generates pydantic.Field attributes with the kwarg example 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. 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.


1: https://docs.pydantic.dev/latest/api/fields/#pydantic.fields.Field
2: https://docs.pydantic.dev/latest/concepts/fields/#customizing-json-schema

@pederhan pederhan added the bug Something isn't working label Apr 4, 2023
@pederhan pederhan added this to the Pydantic V2 milestone Apr 4, 2023
@pederhan pederhan added this to Harbor Apr 4, 2023
@pederhan pederhan added the waiting Waiting for 3rd party label Apr 4, 2023
@pederhan pederhan added documentation Improvements or additions to documentation API Spec Errors or inconsistencies in the API spec labels Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Spec Errors or inconsistencies in the API spec bug Something isn't working documentation Improvements or additions to documentation waiting Waiting for 3rd party
Projects
None yet
Development

No branches or pull requests

1 participant