Repository navigation
Commit 8300f48
[python] fix: explode object query parameters (#24802)
* fix: [python] explode object query parameters
A query parameter whose schema is an object and whose style/explode are left at
their defaults — style: form, explode: true — must go on the wire as one
parameter per entry, keyed by the property name alone. The python client
JSON-encoded the whole object into a single parameter instead.
python/api.mustache appended the object whole, and it was JSON encoded by
ApiClient.parameters_to_url_query, which sees no style or explode. Exploded maps
are now appended entry by entry. parameters_to_url_query's dict branch is left
alone: it is shared by every call site and is still the right fallback for a
parameter that is not exploded.
python/api_client.mustache quoted values and never quoted names. That was
harmless while every name came from baseName in the document, but an exploded
object takes its names from the object, so the names became runtime data for the
first time and a name carrying & or = would break the URL. Names are now quoted
too.
* fix: [python] do not apply a collection format to an exploded object entry
An exploded object query parameter takes its names from the object, so a
property name can collide with the name of a sibling array parameter that
declares a collection format. parameters_to_url_query looked the name up in
collection_formats without checking that the value was a collection, so the
scalar was iterated character by character.
In the petstore fixture, testQueryParameterCollectionFormat declares
context: multi alongside the exploded map language. Calling it with
language={"context": "en"} produced context=e&context=n, and a csv sibling
turned https://x.test into h,t,t,p,s,%3A,/,/,x,.,t,e,s,t.
The collection format now applies only when the value really is a list or a
tuple. Every genuine array parameter is unaffected — multi, csv, ssv and pipes
all serialize byte for byte as before.
Reported by cubic on #24802.
* test: [python] exercise the exploded-name collision guard at runtime
Two runtime tests on parameters_to_url_query in the hand-maintained
petstore sample tests: a scalar entry named like a declared array
parameter goes out as itself, and the declared array parameter still gets
its collection format.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Go3AyndcGwv5tFTwo9aBfy
* fix: [python] explode object query parameters with declared properties
An object with declared properties becomes a model rather than a dict, so it
was flagged isModel, missed the isMap branch and was still json encoded as a
single parameter. With form style and explode a model is now serialized with
sanitize_for_serialization first, so its entries carry the names the
properties have on the wire and unset properties are left out, and then
exploded like a map. A oneOf or anyOf model holding a primitive does not
serialize to a dict and stays a single parameter; deepObject and explode:
false are unchanged.
An exploded entry holding a list now repeats its name per item
(photoUrls=a&photoUrls=b), as java, go and typescript-axios do, instead of
going out as the str() of the list.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix: [python] skip null entries and explode a oneOf holding a list
A null map value went on the wire as k=None and a null list item as l=None,
because parameters_to_url_query quotes str(None). Both exploded branches now
skip a null value and a null item, as kotlin, dart and go do.
The model branch also appends the serialized value rather than the model. For a
oneOf or anyOf holding a primitive that changes nothing on the wire, since
param_serialize runs sanitize_for_serialization over every query parameter
before parameters_to_url_query, but one holding a list now repeats the parameter
name per item instead of sending the list's repr.
Adds a runtime test for the quoting of exploded property names, which only the
generated text covered until now, and one for a model whose optional properties
are left unset.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* refactor: [python] explode query objects in one ApiClient helper
The map and model branches repeated the same loop in every generated
operation. ApiClient.explode_query_object now serializes the value and
returns one pair per entry, so each branch is a single call, and the
helper gets direct unit tests. Comments shrink to one line, the shared
fixture's description names the three combinations it covers, and the
test titles say what they check.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore: [python] regenerate the python-httpx2 samples
They landed on master after this branch was cut, so they did not carry
the exploded query object changes yet.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent a61e05c commit 8300f48
25 files changed
Lines changed: 387 additions & 57 deletions
File tree
- modules/openapi-generator/src
- main/resources/python
- test
- java/org/openapitools/codegen/python
- resources/3_0/python
- samples
- client
- echo_api
- python-disallowAdditionalPropertiesIfNotPresent/openapi_client
- api
- python
- openapi_client
- api
- tests
- others/python-legacy-model-dictionaries/legacy_model_dict_client
- openapi3/client/petstore
- python-aiohttp/petstore_api
- api
- python-httpx-sync/petstore_api
- api
- python-httpx2-sync/petstore_api
- api
- python-httpx2/petstore_api
- api
- python-httpx/petstore_api
- api
- python-lazyImports/petstore_api
- api
- python
- petstore_api
- api
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
350 | 378 | | |
| 379 | + | |
| 380 | + | |
351 | 381 | | |
352 | 382 | | |
353 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
671 | 671 | | |
672 | 672 | | |
673 | 673 | | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
674 | 681 | | |
675 | 682 | | |
676 | 683 | | |
| |||
689 | 696 | | |
690 | 697 | | |
691 | 698 | | |
692 | | - | |
| 699 | + | |
| 700 | + | |
693 | 701 | | |
694 | 702 | | |
695 | 703 | | |
696 | | - | |
| 704 | + | |
697 | 705 | | |
698 | 706 | | |
699 | 707 | | |
| |||
706 | 714 | | |
707 | 715 | | |
708 | 716 | | |
709 | | - | |
| 717 | + | |
710 | 718 | | |
711 | 719 | | |
712 | 720 | | |
713 | 721 | | |
714 | | - | |
| 722 | + | |
| 723 | + | |
715 | 724 | | |
716 | 725 | | |
717 | 726 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
803 | 803 | | |
804 | 804 | | |
805 | 805 | | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
806 | 874 | | |
807 | 875 | | |
808 | 876 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2204 | 2204 | | |
2205 | 2205 | | |
2206 | 2206 | | |
2207 | | - | |
| 2207 | + | |
2208 | 2208 | | |
2209 | 2209 | | |
2210 | 2210 | | |
| |||
2466 | 2466 | | |
2467 | 2467 | | |
2468 | 2468 | | |
2469 | | - | |
| 2469 | + | |
2470 | 2470 | | |
2471 | 2471 | | |
2472 | 2472 | | |
| |||
2728 | 2728 | | |
2729 | 2729 | | |
2730 | 2730 | | |
2731 | | - | |
| 2731 | + | |
2732 | 2732 | | |
2733 | 2733 | | |
2734 | 2734 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
523 | 530 | | |
524 | 531 | | |
525 | 532 | | |
| |||
538 | 545 | | |
539 | 546 | | |
540 | 547 | | |
541 | | - | |
| 548 | + | |
| 549 | + | |
542 | 550 | | |
543 | 551 | | |
544 | 552 | | |
545 | | - | |
| 553 | + | |
546 | 554 | | |
547 | 555 | | |
548 | 556 | | |
| |||
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
558 | | - | |
| 566 | + | |
559 | 567 | | |
560 | 568 | | |
561 | 569 | | |
562 | 570 | | |
563 | | - | |
| 571 | + | |
| 572 | + | |
564 | 573 | | |
565 | 574 | | |
566 | 575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2204 | 2204 | | |
2205 | 2205 | | |
2206 | 2206 | | |
2207 | | - | |
| 2207 | + | |
2208 | 2208 | | |
2209 | 2209 | | |
2210 | 2210 | | |
| |||
2466 | 2466 | | |
2467 | 2467 | | |
2468 | 2468 | | |
2469 | | - | |
| 2469 | + | |
2470 | 2470 | | |
2471 | 2471 | | |
2472 | 2472 | | |
| |||
2728 | 2728 | | |
2729 | 2729 | | |
2730 | 2730 | | |
2731 | | - | |
| 2731 | + | |
2732 | 2732 | | |
2733 | 2733 | | |
2734 | 2734 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
523 | 530 | | |
524 | 531 | | |
525 | 532 | | |
| |||
538 | 545 | | |
539 | 546 | | |
540 | 547 | | |
541 | | - | |
| 548 | + | |
| 549 | + | |
542 | 550 | | |
543 | 551 | | |
544 | 552 | | |
545 | | - | |
| 553 | + | |
546 | 554 | | |
547 | 555 | | |
548 | 556 | | |
| |||
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
558 | | - | |
| 566 | + | |
559 | 567 | | |
560 | 568 | | |
561 | 569 | | |
562 | 570 | | |
563 | | - | |
| 571 | + | |
| 572 | + | |
564 | 573 | | |
565 | 574 | | |
566 | 575 | | |
| |||
0 commit comments