Skip to content

[PYTHON] generate code based on pydantic v2#16549

Closed
wing328 wants to merge 8 commits intomasterfrom
oshmoun-master
Closed

[PYTHON] generate code based on pydantic v2#16549
wing328 wants to merge 8 commits intomasterfrom
oshmoun-master

Conversation

@wing328
Copy link
Member

@wing328 wing328 commented Sep 10, 2023

Based on #16469

Add the option usePydanticV2

There are still errors/warnings in the petstore tests, e.g.

        _obj = Category.parse_obj({
            "id": obj.get("id"),
            "name": obj.get("name") if obj.get("name") is not None else 'default-name'
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
>           if _key not in cls.__properties:
E           TypeError: argument of type 'ModelPrivateAttr' is not iterable

petstore_api/models/category.py:81: TypeError

Warnings:

petstore_api/models/any_of_pig.py:64
  /Users/williamcheng/Code/openapi-generator7/samples/openapi3/client/petstore/python-pydantic-v2/petstore_api/models/any_of_pig.py:64: PydanticDeprecatedSince20: Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
    @validator('actual_instance')

To run the tests, please run make test-all in the folder samples/openapi3/client/petstore/python-pydantic-v2

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date
    
    Commit all changed files.
  • File the PR against the correct branch: master (7.0.1 - patch release), 7.1.x (minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@wing328 wing328 changed the title Oshmoun master [PYTHON] generate code based on pydantic v2 Sep 10, 2023
@wing328 wing328 added this to the 7.0.1 milestone Sep 10, 2023
@ghost ghost mentioned this pull request Sep 15, 2023
@wing328 wing328 modified the milestones: 7.0.1, 7.1.0 Sep 19, 2023
@wing328
Copy link
Member Author

wing328 commented Sep 25, 2023

This PR is no longer needed as python client generator in the latest master will support pydantic v2 directly and users of pydantic v1 can use python-pydantic-v1 client generator instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants