Skip to content

Commit 67d4bf5

Browse files
authored
🐛 fix pr simple head repo type (fix #6)
1 parent 416b7e5 commit 67d4bf5

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

codegen/parser/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,22 @@ def get_schema_override(source: Source) -> Optional[Dict[str, Any]]:
9696
return config.schema_overrides.get(source.pointer.path, None)
9797

9898

99-
def merge_dict(old: dict, new: dict) -> dict:
100-
result = deepcopy(old)
99+
def merge_dict(old: dict, new: dict):
100+
# make change inplace to make json point correct
101101
for key, value in new.items():
102-
result[key] = (
103-
merge_dict(result[key], value)
104-
if isinstance(value, dict) and isinstance(result[key], dict)
102+
old[key] = (
103+
merge_dict(old[key], value)
104+
if isinstance(value, dict) and isinstance(old[key], dict)
105105
else value
106106
)
107-
return result
108107

109108

110109
def schema_from_source(source: Source) -> oas.Schema:
111110
data = source.data
112111
try:
113112
assert isinstance(data, dict)
114113
if overrides := get_schema_override(source):
115-
data = merge_dict(data, overrides)
114+
merge_dict(data, overrides)
116115
return parse_obj_as(oas.Schema, data)
117116
except Exception as e:
118117
raise TypeError(f"Invalid Schema from {source.uri}") from e

githubkit/rest/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6579,7 +6579,7 @@ class PullRequestSimplePropHead(GitHubRestModel):
65796579

65806580
label: str = Field(default=...)
65816581
ref: str = Field(default=...)
6582-
repo: Repository = Field(
6582+
repo: Union[None, Repository] = Field(
65836583
title="Repository", description="A repository on GitHub.", default=...
65846584
)
65856585
sha: str = Field(default=...)

githubkit/rest/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4708,7 +4708,7 @@ class PullRequestSimplePropHeadType(TypedDict):
47084708

47094709
label: str
47104710
ref: str
4711-
repo: RepositoryType
4711+
repo: Union[None, RepositoryType]
47124712
sha: str
47134713
user: Union[None, SimpleUserType]
47144714

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ webhook-types-output = "githubkit/webhooks/types.py"
6767
"-1" = "minus_one"
6868

6969
[tool.codegen.schema-overrides]
70+
# enhancement: issue timeline discriminator
7071
"/components/schemas/labeled-issue-event/properties/event" = { const = "labeled" }
7172
"/components/schemas/unlabeled-issue-event/properties/event" = { const = "unlabeled" }
7273
"/components/schemas/milestoned-issue-event/properties/event" = { const = "milestoned" }
@@ -100,6 +101,12 @@ webhook-types-output = "githubkit/webhooks/types.py"
100101
"/components/schemas/release/properties/body_text" = { type = ["string", "null"] }
101102
"/components/schemas/release/properties/body_html" = { type = ["string", "null"] }
102103

104+
# https://github.com/github/rest-api-description/issues/
105+
"/components/schemas/pull-request-simple/properties/head/properties/repo" = { anyOf = [
106+
{ type = "null" },
107+
{ "$ref" = "#/components/schemas/repository" }
108+
], "$ref" = {} }
109+
103110

104111
[build-system]
105112
requires = ["poetry_core>=1.0.0"]

0 commit comments

Comments
 (0)