Skip to content

Commit 204aa7b

Browse files
authored
✨ Feature: use arbitrary dict type for object with extra properties (#183)
1 parent a3287df commit 204aa7b

Some content is hidden

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

95 files changed

+808
-653
lines changed

codegen/parser/schemas/schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ def get_type_imports(self) -> set[str]:
570570
imports = {"from typing_extensions import TypedDict"}
571571
for prop in self.properties:
572572
imports.update(prop.get_type_imports())
573+
if self.allow_extra:
574+
imports.add("from typing import Any")
575+
imports.add("from typing_extensions import TypeAlias")
573576
return imports
574577

575578
@override

codegen/templates/models/type_group.py.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ from .{{ group_name(group.get_dependency_by_model(model), groups) }} import {{ m
1919
{# model #}
2020
{% for model in group.models %}
2121

22+
{# if model has no property and allows extra properties #}
23+
{# we treat it as arbitrary dict #}
24+
{# TODO: PEP728 TypedDict with extra items #}
25+
{% if not model.properties and model.allow_extra %}
26+
{{ model.class_name }}Type: TypeAlias = dict[str, Any]
27+
{{ build_model_docstring(model) }}
28+
{% else %}
2229
class {{ model.class_name }}Type(TypedDict):
2330
{{ build_model_docstring(model) | indent(4) }}
2431

2532
{% for prop in model.properties %}
2633
{{ prop.get_type_defination() }}
2734
{% endfor %}
35+
{% endif %}
2836

2937
{% endfor %}
3038

githubkit/versions/ghec_v2022_11_28/models/group_0061.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class EnterpriseTeam(GitHubModel):
7373
url: str = Field()
7474
sync_to_organizations: str = Field()
7575
group_id: Missing[Union[str, None]] = Field(default=UNSET)
76+
group_name: Missing[Union[str, None]] = Field(default=UNSET)
7677
html_url: str = Field()
7778
members_url: str = Field()
7879
created_at: datetime = Field()

githubkit/versions/ghec_v2022_11_28/models/group_0232.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616

1717
class CheckAutomatedSecurityFixes(GitHubModel):
18-
"""Check Automated Security Fixes
18+
"""Check Dependabot security updates
1919
20-
Check Automated Security Fixes
20+
Check Dependabot security updates
2121
"""
2222

2323
enabled: bool = Field(
24-
description="Whether automated security fixes are enabled for the repository."
24+
description="Whether Dependabot security updates are enabled for the repository."
2525
)
2626
paused: bool = Field(
27-
description="Whether automated security fixes are paused for the repository."
27+
description="Whether Dependabot security updates are paused for the repository."
2828
)
2929

3030

githubkit/versions/ghec_v2022_11_28/rest/repos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ def check_automated_security_fixes(
27072707
*,
27082708
headers: Optional[Mapping[str, str]] = None,
27092709
) -> Response[CheckAutomatedSecurityFixes, CheckAutomatedSecurityFixesType]:
2710-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository"""
2710+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-dependabot-security-updates-are-enabled-for-a-repository"""
27112711

27122712
from ..models import CheckAutomatedSecurityFixes
27132713

@@ -2730,7 +2730,7 @@ async def async_check_automated_security_fixes(
27302730
*,
27312731
headers: Optional[Mapping[str, str]] = None,
27322732
) -> Response[CheckAutomatedSecurityFixes, CheckAutomatedSecurityFixesType]:
2733-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository"""
2733+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-dependabot-security-updates-are-enabled-for-a-repository"""
27342734

27352735
from ..models import CheckAutomatedSecurityFixes
27362736

@@ -2753,7 +2753,7 @@ def enable_automated_security_fixes(
27532753
*,
27542754
headers: Optional[Mapping[str, str]] = None,
27552755
) -> Response:
2756-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-automated-security-fixes"""
2756+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-dependabot-security-updates"""
27572757

27582758
url = f"/repos/{owner}/{repo}/automated-security-fixes"
27592759

@@ -2772,7 +2772,7 @@ async def async_enable_automated_security_fixes(
27722772
*,
27732773
headers: Optional[Mapping[str, str]] = None,
27742774
) -> Response:
2775-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-automated-security-fixes"""
2775+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-dependabot-security-updates"""
27762776

27772777
url = f"/repos/{owner}/{repo}/automated-security-fixes"
27782778

@@ -2791,7 +2791,7 @@ def disable_automated_security_fixes(
27912791
*,
27922792
headers: Optional[Mapping[str, str]] = None,
27932793
) -> Response:
2794-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-automated-security-fixes"""
2794+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-dependabot-security-updates"""
27952795

27962796
url = f"/repos/{owner}/{repo}/automated-security-fixes"
27972797

@@ -2810,7 +2810,7 @@ async def async_disable_automated_security_fixes(
28102810
*,
28112811
headers: Optional[Mapping[str, str]] = None,
28122812
) -> Response:
2813-
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-automated-security-fixes"""
2813+
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-dependabot-security-updates"""
28142814

28152815
url = f"/repos/{owner}/{repo}/automated-security-fixes"
28162816

githubkit/versions/ghec_v2022_11_28/types/group_0013.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from __future__ import annotations
1111

1212
from datetime import datetime
13-
from typing import Union
14-
from typing_extensions import NotRequired, TypedDict
13+
from typing import Any, Union
14+
from typing_extensions import NotRequired, TypeAlias, TypedDict
1515

1616

1717
class HookDeliveryType(TypedDict):
@@ -44,18 +44,18 @@ class HookDeliveryPropRequestType(TypedDict):
4444
payload: Union[HookDeliveryPropRequestPropPayloadType, None]
4545

4646

47-
class HookDeliveryPropRequestPropHeadersType(TypedDict):
48-
"""HookDeliveryPropRequestPropHeaders
47+
HookDeliveryPropRequestPropHeadersType: TypeAlias = dict[str, Any]
48+
"""HookDeliveryPropRequestPropHeaders
4949
50-
The request headers sent with the webhook delivery.
51-
"""
50+
The request headers sent with the webhook delivery.
51+
"""
5252

5353

54-
class HookDeliveryPropRequestPropPayloadType(TypedDict):
55-
"""HookDeliveryPropRequestPropPayload
54+
HookDeliveryPropRequestPropPayloadType: TypeAlias = dict[str, Any]
55+
"""HookDeliveryPropRequestPropPayload
5656
57-
The webhook payload.
58-
"""
57+
The webhook payload.
58+
"""
5959

6060

6161
class HookDeliveryPropResponseType(TypedDict):
@@ -65,11 +65,11 @@ class HookDeliveryPropResponseType(TypedDict):
6565
payload: Union[str, None]
6666

6767

68-
class HookDeliveryPropResponsePropHeadersType(TypedDict):
69-
"""HookDeliveryPropResponsePropHeaders
68+
HookDeliveryPropResponsePropHeadersType: TypeAlias = dict[str, Any]
69+
"""HookDeliveryPropResponsePropHeaders
7070
71-
The response headers received when the delivery was made.
72-
"""
71+
The response headers received when the delivery was made.
72+
"""
7373

7474

7575
__all__ = (

githubkit/versions/ghec_v2022_11_28/types/group_0041.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
from __future__ import annotations
1111

12-
from typing_extensions import NotRequired, TypedDict
12+
from typing import Any
13+
from typing_extensions import NotRequired, TypeAlias, TypedDict
1314

1415

1516
class AuditLogEventType(TypedDict):
@@ -66,8 +67,9 @@ class AuditLogEventPropActorLocationType(TypedDict):
6667
country_name: NotRequired[str]
6768

6869

69-
class AuditLogEventPropDataType(TypedDict):
70-
"""AuditLogEventPropData"""
70+
AuditLogEventPropDataType: TypeAlias = dict[str, Any]
71+
"""AuditLogEventPropData
72+
"""
7173

7274

7375
class AuditLogEventPropConfigItemsType(TypedDict):

githubkit/versions/ghec_v2022_11_28/types/group_0061.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class EnterpriseTeamType(TypedDict):
4848
url: str
4949
sync_to_organizations: str
5050
group_id: NotRequired[Union[str, None]]
51+
group_name: NotRequired[Union[str, None]]
5152
html_url: str
5253
members_url: str
5354
created_at: datetime

githubkit/versions/ghec_v2022_11_28/types/group_0135.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from datetime import datetime
1313
from typing import Any, Union
14-
from typing_extensions import NotRequired, TypedDict
14+
from typing_extensions import NotRequired, TypeAlias, TypedDict
1515

1616
from .group_0002 import SimpleUserType
1717

@@ -45,8 +45,9 @@ class BaseGistType(TypedDict):
4545
history: NotRequired[list[Any]]
4646

4747

48-
class BaseGistPropFilesType(TypedDict):
49-
"""BaseGistPropFiles"""
48+
BaseGistPropFilesType: TypeAlias = dict[str, Any]
49+
"""BaseGistPropFiles
50+
"""
5051

5152

5253
__all__ = (

githubkit/versions/ghec_v2022_11_28/types/group_0136.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from datetime import datetime
1313
from typing import Any, Union
14-
from typing_extensions import NotRequired, TypedDict
14+
from typing_extensions import NotRequired, TypeAlias, TypedDict
1515

1616
from .group_0002 import SimpleUserType
1717

@@ -66,8 +66,9 @@ class GistSimplePropForkOfType(TypedDict):
6666
history: NotRequired[list[Any]]
6767

6868

69-
class GistSimplePropForkOfPropFilesType(TypedDict):
70-
"""GistSimplePropForkOfPropFiles"""
69+
GistSimplePropForkOfPropFilesType: TypeAlias = dict[str, Any]
70+
"""GistSimplePropForkOfPropFiles
71+
"""
7172

7273

7374
__all__ = (

0 commit comments

Comments
 (0)