Skip to content

enhance python openapi generator#22600

Open
padznich wants to merge 28 commits intoOpenAPITools:masterfrom
padznich:enhance-python-openapi-generator
Open

enhance python openapi generator#22600
padznich wants to merge 28 commits intoOpenAPITools:masterfrom
padznich:enhance-python-openapi-generator

Conversation

@padznich
Copy link
Contributor

@padznich padznich commented Dec 30, 2025

for Python 3.11+
anyOf / allOf Root model based
StrEnum, IntEnum

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@cbornet
@tomplus
@krjakbrjak
@fa0311
@multani

Fixes issues:


Summary by cubic

Modernizes the Python generator for 3.11+ by adopting Pydantic v2 APIs and RootModel-based unions for anyOf/oneOf. Adds StrEnum/IntEnum, Literal-typed inline enums, simplifies serialization, and updates client/header handling for urllib3 v2.

  • New Features

    • anyOf/oneOf now use RootModel[Union[...]] with optional discriminator.
    • Inline enum properties generate typing.Literal[...] types.
    • String and integer enums generate StrEnum/IntEnum.
    • Switch to Pydantic v2 methods (model_validate, model_dump, model_validate_json, model_dump_json).
    • Cleaner exceptions with unified body/data output.
    • ApiClient uses getheader/getheaders and model_validate for deserialization.
  • Migration

    • Requires Python 3.11+; urllib3 >= 2.1.0.
    • Replace:
      • from_json → model_validate_json
      • to_json → model_dump_json(by_alias=True, exclude_unset=True)
      • from_dict → model_validate
      • to_dict → model_dump(by_alias=True)
    • anyOf/oneOf values are on .root.
    • ApiClient now calls klass.model_validate(data); response headers use getheaders() (list of pairs) instead of a mapping. Adjust code that reads headers accordingly.

Written for commit 82bb97c. Summary will update on new commits.

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

Labels

Client: Python Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants