Skip to content

Commit 44adc92

Browse files
authored
✨ reduce rest api webhook schemas
1 parent ba3dfee commit 44adc92

File tree

8 files changed

+672
-37403
lines changed

8 files changed

+672
-37403
lines changed

codegen/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import shutil
22
from pathlib import Path
3-
from typing import Any, Dict, Union, Optional
3+
from typing import Any, Dict
44

55
import httpx
66
import tomli
@@ -116,6 +116,15 @@ def build_webhook(data: WebhookData, config: Config):
116116
logger.info("Successfully generated webhook codes!")
117117

118118

119+
def _patch_openapi_spec(spec: Dict[str, Any]):
120+
spec.pop("webhooks", None)
121+
for name in list(spec["components"]["schemas"].keys()):
122+
if name.startswith("webhook-config"):
123+
continue
124+
elif name.startswith("webhook"):
125+
del spec["components"]["schemas"][name]
126+
127+
119128
def build():
120129
config = load_config()
121130
logger.info(f"Loaded config: {config!r}")
@@ -125,6 +134,7 @@ def build():
125134
logger.info(f"Getting schema from {source.uri} succeeded!")
126135

127136
logger.info("Start parsing OpenAPI spec...")
137+
_patch_openapi_spec(source.root)
128138
parsed_data = parse_openapi_spec(source, config)
129139
logger.info(
130140
"Successfully parsed OpenAPI spec: "

codegen/parser/schemas/model_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _is_model_merge(
121121
# try merge
122122
try:
123123
prop = _merge_property(
124-
source,
124+
source / "allof" / "merged" / name,
125125
properties[prop.name],
126126
prop,
127127
concat_snake_name(class_name, "prop", prop.name),
@@ -169,7 +169,7 @@ def _merge_schema(
169169
or _is_list_merge(source, name, prefix, first, second)
170170
):
171171
return schema
172-
raise RuntimeError(f"Cannot merge schema {first!r} {second!r}")
172+
raise RuntimeError(f"Cannot merge schema for {name}: {first!r}; {second!r}")
173173

174174

175175
def _merge_property(

githubkit/rest/migrations.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def get_import_status(
387387
response_model=Import,
388388
error_models={
389389
"404": BasicError,
390+
"503": BasicError,
390391
},
391392
)
392393

@@ -403,6 +404,7 @@ async def async_get_import_status(
403404
response_model=Import,
404405
error_models={
405406
"404": BasicError,
407+
"503": BasicError,
406408
},
407409
)
408410

@@ -452,6 +454,7 @@ def start_import(
452454
error_models={
453455
"422": ValidationError,
454456
"404": BasicError,
457+
"503": BasicError,
455458
},
456459
)
457460

@@ -501,6 +504,7 @@ async def async_start_import(
501504
error_models={
502505
"422": ValidationError,
503506
"404": BasicError,
507+
"503": BasicError,
504508
},
505509
)
506510

@@ -514,6 +518,9 @@ def cancel_import(
514518
return self._github.request(
515519
"DELETE",
516520
url,
521+
error_models={
522+
"503": BasicError,
523+
},
517524
)
518525

519526
async def async_cancel_import(
@@ -526,6 +533,9 @@ async def async_cancel_import(
526533
return await self._github.arequest(
527534
"DELETE",
528535
url,
536+
error_models={
537+
"503": BasicError,
538+
},
529539
)
530540

531541
@overload
@@ -574,6 +584,9 @@ def update_import(
574584
url,
575585
json=exclude_unset(json),
576586
response_model=Import,
587+
error_models={
588+
"503": BasicError,
589+
},
577590
)
578591

579592
@overload
@@ -622,6 +635,9 @@ async def async_update_import(
622635
url,
623636
json=exclude_unset(json),
624637
response_model=Import,
638+
error_models={
639+
"503": BasicError,
640+
},
625641
)
626642

627643
def get_commit_authors(
@@ -643,6 +659,7 @@ def get_commit_authors(
643659
response_model=List[PorterAuthor],
644660
error_models={
645661
"404": BasicError,
662+
"503": BasicError,
646663
},
647664
)
648665

@@ -665,6 +682,7 @@ async def async_get_commit_authors(
665682
response_model=List[PorterAuthor],
666683
error_models={
667684
"404": BasicError,
685+
"503": BasicError,
668686
},
669687
)
670688

@@ -718,6 +736,7 @@ def map_commit_author(
718736
error_models={
719737
"422": ValidationError,
720738
"404": BasicError,
739+
"503": BasicError,
721740
},
722741
)
723742

@@ -771,6 +790,7 @@ async def async_map_commit_author(
771790
error_models={
772791
"422": ValidationError,
773792
"404": BasicError,
793+
"503": BasicError,
774794
},
775795
)
776796

@@ -785,6 +805,9 @@ def get_large_files(
785805
"GET",
786806
url,
787807
response_model=List[PorterLargeFile],
808+
error_models={
809+
"503": BasicError,
810+
},
788811
)
789812

790813
async def async_get_large_files(
@@ -798,6 +821,9 @@ async def async_get_large_files(
798821
"GET",
799822
url,
800823
response_model=List[PorterLargeFile],
824+
error_models={
825+
"503": BasicError,
826+
},
801827
)
802828

803829
@overload
@@ -841,6 +867,7 @@ def set_lfs_preference(
841867
response_model=Import,
842868
error_models={
843869
"422": ValidationError,
870+
"503": BasicError,
844871
},
845872
)
846873

@@ -885,6 +912,7 @@ async def async_set_lfs_preference(
885912
response_model=Import,
886913
error_models={
887914
"422": ValidationError,
915+
"503": BasicError,
888916
},
889917
)
890918

0 commit comments

Comments
 (0)