Feature/23032 alternative

Closed
AN
5mo ago
+59235-14

Alternative solution to the #23032 where sync methods do not use coroutine but instead they share a common code with async methods.

PR checklist

  • [ X ] Read the contribution guidelines.
  • [ X ] 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.
  • [ X ] 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 (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10) @multani (2023/10)


Summary by cubic

Adds supportHttpxSync to the Python httpx generator to create synchronous _sync variants for each API method in the same class, using a real httpx.Client (no coroutine wrapping). This exposes both async and blocking methods without a separate library.

  • New Features

    • New supportHttpxSync option in the Python generator (only for httpx; ignored otherwise with a warning).
    • Generates _sync, _sync_with_http_info, and _sync_without_preload_content alongside async methods.
    • ApiClient adds call_api_sync(), a sync context manager (__enter__/__exit__), and close_sync().
    • httpx REST layer adds a dedicated httpx.Client, request_sync(), close_sync(), and RESTResponse.read_sync().
    • Docs updated, new petstore sample (bin/configs/python-httpx-sync.yaml and samples/.../python-httpx-sync), and CI workflows include the sample.
  • Migration

    • Enable with additionalProperties.supportHttpxSync=true when generating a Python client with library: httpx.
    • Async methods are unchanged; call method_sync(...) for blocking usage.