Skip to content

Commit c2f5930

Browse files
authored
🐛 Fix: array type query param name (#250)
1 parent d7376c8 commit c2f5930

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1486
-1435
lines changed

codegen/templates/rest/_request.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ if self._github.config.rest_api_validate_body:
9393
"{{ endpoint.method | upper }}",
9494
url,
9595
{% if endpoint.query_params %}
96-
params=exclude_unset(params),
96+
params=exclude_unset(parse_query_params(params)),
9797
{% endif %}
9898
{% if endpoint.request_body %}
9999
{% set name = TYPE_MAPPING[endpoint.request_body.type] %}

codegen/templates/rest/client.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from typing import TYPE_CHECKING, Literal, Optional, Annotated, overload
1616
from pydantic import BaseModel, Field
1717

1818
from githubkit.typing import Missing, UnsetType
19-
from githubkit.utils import exclude_unset, UNSET
19+
from githubkit.utils import UNSET, exclude_unset, parse_query_params
2020
from githubkit.compat import model_dump, type_validate_python
2121

2222
if TYPE_CHECKING:

githubkit/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ def is_async(obj: Any) -> bool:
8282
return inspect.iscoroutinefunction(func_)
8383

8484

85+
def parse_query_params(params: dict[str, Any]) -> dict[str, Any]:
86+
"""GitHub query params use `name[]` format to send an array.
87+
88+
See also: https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api?apiVersion=2022-11-28
89+
"""
90+
new_params: dict[str, Any] = {}
91+
for key, value in params.items():
92+
if isinstance(value, list):
93+
key = f"{key}[]"
94+
new_params[key] = value
95+
return new_params
96+
97+
8598
class TaggedUnion(Generic[T]):
8699
__slots__ = ("discriminator", "tag", "type_")
87100

githubkit/versions/ghec_v2022_11_28/rest/actions.py

Lines changed: 65 additions & 65 deletions
Large diffs are not rendered by default.

githubkit/versions/ghec_v2022_11_28/rest/activity.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from githubkit.compat import model_dump, type_validate_python
1919
from githubkit.typing import Missing, UnsetType
20-
from githubkit.utils import UNSET, exclude_unset
20+
from githubkit.utils import UNSET, exclude_unset, parse_query_params
2121

2222
if TYPE_CHECKING:
2323
from datetime import datetime
@@ -113,7 +113,7 @@ def list_public_events(
113113
return self._github.request(
114114
"GET",
115115
url,
116-
params=exclude_unset(params),
116+
params=exclude_unset(parse_query_params(params)),
117117
headers=exclude_unset(headers),
118118
stream=stream,
119119
response_model=list[Event],
@@ -159,7 +159,7 @@ async def async_list_public_events(
159159
return await self._github.arequest(
160160
"GET",
161161
url,
162-
params=exclude_unset(params),
162+
params=exclude_unset(parse_query_params(params)),
163163
headers=exclude_unset(headers),
164164
stream=stream,
165165
response_model=list[Event],
@@ -287,7 +287,7 @@ def list_public_events_for_repo_network(
287287
return self._github.request(
288288
"GET",
289289
url,
290-
params=exclude_unset(params),
290+
params=exclude_unset(parse_query_params(params)),
291291
headers=exclude_unset(headers),
292292
stream=stream,
293293
response_model=list[Event],
@@ -331,7 +331,7 @@ async def async_list_public_events_for_repo_network(
331331
return await self._github.arequest(
332332
"GET",
333333
url,
334-
params=exclude_unset(params),
334+
params=exclude_unset(parse_query_params(params)),
335335
headers=exclude_unset(headers),
336336
stream=stream,
337337
response_model=list[Event],
@@ -380,7 +380,7 @@ def list_notifications_for_authenticated_user(
380380
return self._github.request(
381381
"GET",
382382
url,
383-
params=exclude_unset(params),
383+
params=exclude_unset(parse_query_params(params)),
384384
headers=exclude_unset(headers),
385385
stream=stream,
386386
response_model=list[Thread],
@@ -430,7 +430,7 @@ async def async_list_notifications_for_authenticated_user(
430430
return await self._github.arequest(
431431
"GET",
432432
url,
433-
params=exclude_unset(params),
433+
params=exclude_unset(parse_query_params(params)),
434434
headers=exclude_unset(headers),
435435
stream=stream,
436436
response_model=list[Thread],
@@ -1090,7 +1090,7 @@ def list_public_org_events(
10901090
return self._github.request(
10911091
"GET",
10921092
url,
1093-
params=exclude_unset(params),
1093+
params=exclude_unset(parse_query_params(params)),
10941094
headers=exclude_unset(headers),
10951095
stream=stream,
10961096
response_model=list[Event],
@@ -1129,7 +1129,7 @@ async def async_list_public_org_events(
11291129
return await self._github.arequest(
11301130
"GET",
11311131
url,
1132-
params=exclude_unset(params),
1132+
params=exclude_unset(parse_query_params(params)),
11331133
headers=exclude_unset(headers),
11341134
stream=stream,
11351135
response_model=list[Event],
@@ -1169,7 +1169,7 @@ def list_repo_events(
11691169
return self._github.request(
11701170
"GET",
11711171
url,
1172-
params=exclude_unset(params),
1172+
params=exclude_unset(parse_query_params(params)),
11731173
headers=exclude_unset(headers),
11741174
stream=stream,
11751175
response_model=list[Event],
@@ -1209,7 +1209,7 @@ async def async_list_repo_events(
12091209
return await self._github.arequest(
12101210
"GET",
12111211
url,
1212-
params=exclude_unset(params),
1212+
params=exclude_unset(parse_query_params(params)),
12131213
headers=exclude_unset(headers),
12141214
stream=stream,
12151215
response_model=list[Event],
@@ -1256,7 +1256,7 @@ def list_repo_notifications_for_authenticated_user(
12561256
return self._github.request(
12571257
"GET",
12581258
url,
1259-
params=exclude_unset(params),
1259+
params=exclude_unset(parse_query_params(params)),
12601260
headers=exclude_unset(headers),
12611261
stream=stream,
12621262
response_model=list[Thread],
@@ -1303,7 +1303,7 @@ async def async_list_repo_notifications_for_authenticated_user(
13031303
return await self._github.arequest(
13041304
"GET",
13051305
url,
1306-
params=exclude_unset(params),
1306+
params=exclude_unset(parse_query_params(params)),
13071307
headers=exclude_unset(headers),
13081308
stream=stream,
13091309
response_model=list[Thread],
@@ -1507,7 +1507,7 @@ def list_stargazers_for_repo(
15071507
return self._github.request(
15081508
"GET",
15091509
url,
1510-
params=exclude_unset(params),
1510+
params=exclude_unset(parse_query_params(params)),
15111511
headers=exclude_unset(headers),
15121512
stream=stream,
15131513
response_model=Union[list[SimpleUser], list[Stargazer]],
@@ -1558,7 +1558,7 @@ async def async_list_stargazers_for_repo(
15581558
return await self._github.arequest(
15591559
"GET",
15601560
url,
1561-
params=exclude_unset(params),
1561+
params=exclude_unset(parse_query_params(params)),
15621562
headers=exclude_unset(headers),
15631563
stream=stream,
15641564
response_model=Union[list[SimpleUser], list[Stargazer]],
@@ -1600,7 +1600,7 @@ def list_watchers_for_repo(
16001600
return self._github.request(
16011601
"GET",
16021602
url,
1603-
params=exclude_unset(params),
1603+
params=exclude_unset(parse_query_params(params)),
16041604
headers=exclude_unset(headers),
16051605
stream=stream,
16061606
response_model=list[SimpleUser],
@@ -1639,7 +1639,7 @@ async def async_list_watchers_for_repo(
16391639
return await self._github.arequest(
16401640
"GET",
16411641
url,
1642-
params=exclude_unset(params),
1642+
params=exclude_unset(parse_query_params(params)),
16431643
headers=exclude_unset(headers),
16441644
stream=stream,
16451645
response_model=list[SimpleUser],
@@ -1942,7 +1942,7 @@ def list_repos_starred_by_authenticated_user(
19421942
return self._github.request(
19431943
"GET",
19441944
url,
1945-
params=exclude_unset(params),
1945+
params=exclude_unset(parse_query_params(params)),
19461946
headers=exclude_unset(headers),
19471947
stream=stream,
19481948
response_model=list[Repository],
@@ -1991,7 +1991,7 @@ async def async_list_repos_starred_by_authenticated_user(
19911991
return await self._github.arequest(
19921992
"GET",
19931993
url,
1994-
params=exclude_unset(params),
1994+
params=exclude_unset(parse_query_params(params)),
19951995
headers=exclude_unset(headers),
19961996
stream=stream,
19971997
response_model=list[Repository],
@@ -2242,7 +2242,7 @@ def list_watched_repos_for_authenticated_user(
22422242
return self._github.request(
22432243
"GET",
22442244
url,
2245-
params=exclude_unset(params),
2245+
params=exclude_unset(parse_query_params(params)),
22462246
headers=exclude_unset(headers),
22472247
stream=stream,
22482248
response_model=list[MinimalRepository],
@@ -2283,7 +2283,7 @@ async def async_list_watched_repos_for_authenticated_user(
22832283
return await self._github.arequest(
22842284
"GET",
22852285
url,
2286-
params=exclude_unset(params),
2286+
params=exclude_unset(parse_query_params(params)),
22872287
headers=exclude_unset(headers),
22882288
stream=stream,
22892289
response_model=list[MinimalRepository],
@@ -2328,7 +2328,7 @@ def list_events_for_authenticated_user(
23282328
return self._github.request(
23292329
"GET",
23302330
url,
2331-
params=exclude_unset(params),
2331+
params=exclude_unset(parse_query_params(params)),
23322332
headers=exclude_unset(headers),
23332333
stream=stream,
23342334
response_model=list[Event],
@@ -2369,7 +2369,7 @@ async def async_list_events_for_authenticated_user(
23692369
return await self._github.arequest(
23702370
"GET",
23712371
url,
2372-
params=exclude_unset(params),
2372+
params=exclude_unset(parse_query_params(params)),
23732373
headers=exclude_unset(headers),
23742374
stream=stream,
23752375
response_model=list[Event],
@@ -2411,7 +2411,7 @@ def list_org_events_for_authenticated_user(
24112411
return self._github.request(
24122412
"GET",
24132413
url,
2414-
params=exclude_unset(params),
2414+
params=exclude_unset(parse_query_params(params)),
24152415
headers=exclude_unset(headers),
24162416
stream=stream,
24172417
response_model=list[Event],
@@ -2453,7 +2453,7 @@ async def async_list_org_events_for_authenticated_user(
24532453
return await self._github.arequest(
24542454
"GET",
24552455
url,
2456-
params=exclude_unset(params),
2456+
params=exclude_unset(parse_query_params(params)),
24572457
headers=exclude_unset(headers),
24582458
stream=stream,
24592459
response_model=list[Event],
@@ -2492,7 +2492,7 @@ def list_public_events_for_user(
24922492
return self._github.request(
24932493
"GET",
24942494
url,
2495-
params=exclude_unset(params),
2495+
params=exclude_unset(parse_query_params(params)),
24962496
headers=exclude_unset(headers),
24972497
stream=stream,
24982498
response_model=list[Event],
@@ -2531,7 +2531,7 @@ async def async_list_public_events_for_user(
25312531
return await self._github.arequest(
25322532
"GET",
25332533
url,
2534-
params=exclude_unset(params),
2534+
params=exclude_unset(parse_query_params(params)),
25352535
headers=exclude_unset(headers),
25362536
stream=stream,
25372537
response_model=list[Event],
@@ -2573,7 +2573,7 @@ def list_received_events_for_user(
25732573
return self._github.request(
25742574
"GET",
25752575
url,
2576-
params=exclude_unset(params),
2576+
params=exclude_unset(parse_query_params(params)),
25772577
headers=exclude_unset(headers),
25782578
stream=stream,
25792579
response_model=list[Event],
@@ -2615,7 +2615,7 @@ async def async_list_received_events_for_user(
26152615
return await self._github.arequest(
26162616
"GET",
26172617
url,
2618-
params=exclude_unset(params),
2618+
params=exclude_unset(parse_query_params(params)),
26192619
headers=exclude_unset(headers),
26202620
stream=stream,
26212621
response_model=list[Event],
@@ -2654,7 +2654,7 @@ def list_received_public_events_for_user(
26542654
return self._github.request(
26552655
"GET",
26562656
url,
2657-
params=exclude_unset(params),
2657+
params=exclude_unset(parse_query_params(params)),
26582658
headers=exclude_unset(headers),
26592659
stream=stream,
26602660
response_model=list[Event],
@@ -2693,7 +2693,7 @@ async def async_list_received_public_events_for_user(
26932693
return await self._github.arequest(
26942694
"GET",
26952695
url,
2696-
params=exclude_unset(params),
2696+
params=exclude_unset(parse_query_params(params)),
26972697
headers=exclude_unset(headers),
26982698
stream=stream,
26992699
response_model=list[Event],
@@ -2744,7 +2744,7 @@ def list_repos_starred_by_user(
27442744
return self._github.request(
27452745
"GET",
27462746
url,
2747-
params=exclude_unset(params),
2747+
params=exclude_unset(parse_query_params(params)),
27482748
headers=exclude_unset(headers),
27492749
stream=stream,
27502750
response_model=Union[list[StarredRepository], list[Repository]],
@@ -2795,7 +2795,7 @@ async def async_list_repos_starred_by_user(
27952795
return await self._github.arequest(
27962796
"GET",
27972797
url,
2798-
params=exclude_unset(params),
2798+
params=exclude_unset(parse_query_params(params)),
27992799
headers=exclude_unset(headers),
28002800
stream=stream,
28012801
response_model=Union[list[StarredRepository], list[Repository]],
@@ -2833,7 +2833,7 @@ def list_repos_watched_by_user(
28332833
return self._github.request(
28342834
"GET",
28352835
url,
2836-
params=exclude_unset(params),
2836+
params=exclude_unset(parse_query_params(params)),
28372837
headers=exclude_unset(headers),
28382838
stream=stream,
28392839
response_model=list[MinimalRepository],
@@ -2871,7 +2871,7 @@ async def async_list_repos_watched_by_user(
28712871
return await self._github.arequest(
28722872
"GET",
28732873
url,
2874-
params=exclude_unset(params),
2874+
params=exclude_unset(parse_query_params(params)),
28752875
headers=exclude_unset(headers),
28762876
stream=stream,
28772877
response_model=list[MinimalRepository],

0 commit comments

Comments
 (0)