Skip to content

Commit 106b51b

Browse files
authored
✨ allow extra field and fix boolean default
1 parent c31f384 commit 106b51b

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

codegen/parser/schemas/bool_schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from ...source import Source
44
from .schema import BoolSchema
5+
from ..utils import build_boolean
56

67

78
def build_bool_schema(source: Source) -> BoolSchema:
@@ -13,6 +14,8 @@ def build_bool_schema(source: Source) -> BoolSchema:
1314
return BoolSchema(
1415
title=data.title,
1516
description=data.description,
16-
default=data.default,
17+
default=build_boolean(data.default)
18+
if data.default is not None
19+
else data.default,
1720
examples=data.examples or (data.example and [data.example]),
1821
)

codegen/parser/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def concat_snake_name(*names: str) -> str:
7070
return "_".join(snake_case(name) for name in names)
7171

7272

73+
def build_boolean(value: bool | str) -> bool:
74+
if isinstance(value, bool):
75+
return value
76+
return value.lower() not in {"false", "f", "no", "n", "0"}
77+
78+
7379
def build_class_name(name: str) -> str:
7480
config = get_config()
7581
class_name = fix_reserved_words(pascal_case(name))

codegen/templates/models/models.py.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ See https://github.com/github/rest-api-description for more information.
88

99
from __future__ import annotations
1010

11+
from pydantic import BaseModel, Extra
12+
1113
{% for model in models %}
1214
{% for import_ in model.get_model_imports() %}
1315
{{ import_ }}
1416
{% endfor %}
1517
{% endfor %}
1618

17-
class GitHubRestModel(BaseModel, allow_population_by_field_name=True):
19+
class GitHubRestModel(BaseModel, extra=Extra.allow, allow_population_by_field_name=True):
1820
...
1921

2022
{# model #}

githubkit/rest/models.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from githubkit.utils import UNSET, Unset
1616

1717

18-
class GitHubRestModel(BaseModel, allow_population_by_field_name=True):
18+
class GitHubRestModel(
19+
BaseModel, extra=Extra.allow, allow_population_by_field_name=True
20+
):
1921
...
2022

2123

@@ -1739,6 +1741,10 @@ class OrganizationSecretScanningAlert(GitHubRestModel):
17391741
description="The time that push protection was bypassed in ISO 8601 format: `YYYY-MM-DDTHH:MM:SSZ`.",
17401742
default=UNSET,
17411743
)
1744+
resolution_comment: Union[Unset, Union[str, None]] = Field(
1745+
description="The comment that was optionally added when this alert was closed",
1746+
default=UNSET,
1747+
)
17421748

17431749

17441750
class AdvancedSecurityActiveCommittersUser(GitHubRestModel):
@@ -6708,6 +6714,10 @@ class DependencyGraphDiffItems(GitHubRestModel):
67086714
vulnerabilities: List[DependencyGraphDiffItemsPropVulnerabilitiesItems] = Field(
67096715
default=...
67106716
)
6717+
scope: Literal["unknown", "runtime", "development"] = Field(
6718+
description="Where the dependency is utilized. `development` means that the dependency is only utilized in the development environment. `runtime` means that the dependency is utilized at runtime and in the development environment.",
6719+
default=...,
6720+
)
67116721

67126722

67136723
class DependencyGraphDiffItemsPropVulnerabilitiesItems(GitHubRestModel):
@@ -9482,6 +9492,10 @@ class SecretScanningAlert(GitHubRestModel):
94829492
description="The time that push protection was bypassed in ISO 8601 format: `YYYY-MM-DDTHH:MM:SSZ`.",
94839493
default=UNSET,
94849494
)
9495+
resolution_comment: Union[Unset, Union[str, None]] = Field(
9496+
description="The comment that was optionally added when this alert was closed",
9497+
default=UNSET,
9498+
)
94859499

94869500

94879501
class SecretScanningLocationCommit(GitHubRestModel):
@@ -12431,7 +12445,7 @@ class ReposOwnerRepoAutolinksPostBody(GitHubRestModel):
1243112445
)
1243212446
is_alphanumeric: Union[Unset, bool] = Field(
1243312447
description="Whether this autolink reference matches alphanumeric characters. If true, the `<num>` parameter of the `url_template` matches alphanumeric characters `A-Z` (case insensitive), `0-9`, and `-`. If false, this autolink reference only matches numeric characters.",
12434-
default="true",
12448+
default=True,
1243512449
)
1243612450

1243712451

@@ -15284,6 +15298,10 @@ class ReposOwnerRepoSecretScanningAlertsAlertNumberPatchBody(GitHubRestModel):
1528415298
description="**Required when the `state` is `resolved`.** The reason for resolving the alert.",
1528515299
default=UNSET,
1528615300
)
15301+
resolution_comment: Union[Unset, Union[str, None]] = Field(
15302+
description="Sets an optional comment when closing an alert. Must be null when changing `state` to `open`.",
15303+
default=UNSET,
15304+
)
1528715305

1528815306

1528915307
class ReposOwnerRepoStatusesShaPostBody(GitHubRestModel):

githubkit/rest/repos.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def create_autolink(
714714
data: Unset = UNSET,
715715
key_prefix: str,
716716
url_template: str,
717-
is_alphanumeric: Union[Unset, bool] = "true",
717+
is_alphanumeric: Union[Unset, bool] = True,
718718
) -> "Response[Autolink]":
719719
...
720720

@@ -760,7 +760,7 @@ async def async_create_autolink(
760760
data: Unset = UNSET,
761761
key_prefix: str,
762762
url_template: str,
763-
is_alphanumeric: Union[Unset, bool] = "true",
763+
is_alphanumeric: Union[Unset, bool] = True,
764764
) -> "Response[Autolink]":
765765
...
766766

@@ -7847,6 +7847,7 @@ def update_information_about_pages_site(
78477847
error_models={
78487848
"422": ValidationError,
78497849
"400": BasicError,
7850+
"409": BasicError,
78507851
},
78517852
)
78527853

@@ -8010,6 +8011,7 @@ async def async_update_information_about_pages_site(
80108011
error_models={
80118012
"422": ValidationError,
80128013
"400": BasicError,
8014+
"409": BasicError,
80138015
},
80148016
)
80158017

@@ -8192,6 +8194,7 @@ def delete_pages_site(
81928194
error_models={
81938195
"422": ValidationError,
81948196
"404": BasicError,
8197+
"409": BasicError,
81958198
},
81968199
)
81978200

@@ -8208,6 +8211,7 @@ async def async_delete_pages_site(
82088211
error_models={
82098212
"422": ValidationError,
82108213
"404": BasicError,
8214+
"409": BasicError,
82118215
},
82128216
)
82138217

githubkit/rest/secret_scanning.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ def update_alert(
314314
None, Literal["false_positive", "wont_fix", "revoked", "used_in_tests"]
315315
],
316316
] = UNSET,
317+
resolution_comment: Union[Unset, Union[str, None]] = UNSET,
317318
) -> "Response[SecretScanningAlert]":
318319
...
319320

@@ -375,6 +376,7 @@ async def async_update_alert(
375376
None, Literal["false_positive", "wont_fix", "revoked", "used_in_tests"]
376377
],
377378
] = UNSET,
379+
resolution_comment: Union[Unset, Union[str, None]] = UNSET,
378380
) -> "Response[SecretScanningAlert]":
379381
...
380382

githubkit/rest/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ class OrganizationSecretScanningAlertType(TypedDict):
11081108
push_protection_bypassed: NotRequired[Union[bool, None]]
11091109
push_protection_bypassed_by: NotRequired[Union[None, SimpleUserType]]
11101110
push_protection_bypassed_at: NotRequired[Union[datetime, None]]
1111+
resolution_comment: NotRequired[Union[str, None]]
11111112

11121113

11131114
class AdvancedSecurityActiveCommittersUserType(TypedDict):
@@ -4940,6 +4941,7 @@ class DependencyGraphDiffItemsType(TypedDict):
49404941
license_: Union[str, None]
49414942
source_repository_url: Union[str, None]
49424943
vulnerabilities: List[DependencyGraphDiffItemsPropVulnerabilitiesItemsType]
4944+
scope: Literal["unknown", "runtime", "development"]
49434945

49444946

49454947
class DependencyGraphDiffItemsPropVulnerabilitiesItemsType(TypedDict):
@@ -7081,6 +7083,7 @@ class SecretScanningAlertType(TypedDict):
70817083
push_protection_bypassed: NotRequired[Union[bool, None]]
70827084
push_protection_bypassed_by: NotRequired[Union[None, SimpleUserType]]
70837085
push_protection_bypassed_at: NotRequired[Union[datetime, None]]
7086+
resolution_comment: NotRequired[Union[str, None]]
70847087

70857088

70867089
class SecretScanningLocationCommitType(TypedDict):
@@ -10854,6 +10857,7 @@ class ReposOwnerRepoSecretScanningAlertsAlertNumberPatchBodyType(TypedDict):
1085410857
resolution: NotRequired[
1085510858
Union[None, Literal["false_positive", "wont_fix", "revoked", "used_in_tests"]]
1085610859
]
10860+
resolution_comment: NotRequired[Union[str, None]]
1085710861

1085810862

1085910863
class ReposOwnerRepoStatusesShaPostBodyType(TypedDict):

0 commit comments

Comments
 (0)