1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-18 23:15:09 +00:00

Fix parser

This commit is contained in:
RGBCube 2022-06-26 17:21:55 +03:00
parent 6682738c74
commit 9e97298f7c
2 changed files with 20 additions and 18 deletions

View file

@ -6,17 +6,6 @@ if TYPE_CHECKING:
from typing_extensions import NotRequired from typing_extensions import NotRequired
class Repository(TypedDict):
# Example: 42
id: NotRequired[int]
# Example: MDEwOlJlcG9zaXRvcnkxMjk2MjY5
node_id: NotRequired[str]
# Example: Team Environment
name: NotRequired[str]
# Example: octocat/Hello-World
full_name: NotRequired[str]
class LicenseSimple(TypedDict): class LicenseSimple(TypedDict):
# Example: mit # Example: mit
key: NotRequired[str] key: NotRequired[str]
@ -31,7 +20,6 @@ class LicenseSimple(TypedDict):
node_id: NotRequired[str] node_id: NotRequired[str]
# Format: uri # Format: uri
html_url: NotRequired[str] html_url: NotRequired[str]
license: NotRequired[Optional[LicenseSimple]]
class SimpleUser(TypedDict): class SimpleUser(TypedDict):
@ -82,8 +70,6 @@ class SimpleUser(TypedDict):
site_admin: NotRequired[bool] site_admin: NotRequired[bool]
# Example: "2020-07-09T00:17:55Z" # Example: "2020-07-09T00:17:55Z"
starred_at: NotRequired[str] starred_at: NotRequired[str]
organization: NotRequired[Optional[SimpleUser]]
forks: NotRequired[int]
class Permissions(TypedDict): class Permissions(TypedDict):
@ -92,7 +78,6 @@ class Permissions(TypedDict):
triage: NotRequired[bool] triage: NotRequired[bool]
push: NotRequired[bool] push: NotRequired[bool]
maintain: NotRequired[bool] maintain: NotRequired[bool]
permissions: NotRequired[Permissions]
class SimpleUser(TypedDict): class SimpleUser(TypedDict):
@ -143,6 +128,21 @@ class SimpleUser(TypedDict):
site_admin: NotRequired[bool] site_admin: NotRequired[bool]
# Example: "2020-07-09T00:17:55Z" # Example: "2020-07-09T00:17:55Z"
starred_at: NotRequired[str] starred_at: NotRequired[str]
class Repository(TypedDict):
# Example: 42
id: NotRequired[int]
# Example: MDEwOlJlcG9zaXRvcnkxMjk2MjY5
node_id: NotRequired[str]
# Example: Team Environment
name: NotRequired[str]
# Example: octocat/Hello-World
full_name: NotRequired[str]
license: NotRequired[Optional[LicenseSimple]]
organization: NotRequired[Optional[SimpleUser]]
forks: NotRequired[int]
permissions: NotRequired[Permissions]
owner: NotRequired[SimpleUser] owner: NotRequired[SimpleUser]
private: NotRequired[bool] private: NotRequired[bool]
# Format: uri # Format: uri

View file

@ -119,7 +119,7 @@ def generate_typed_dicts_from_json_schema(
total = ", total=False" if obj.get("additionalProperties") else "" total = ", total=False" if obj.get("additionalProperties") else ""
annotation = obj_title = obj.get("title", title).replace(" ", "") annotation = obj_title = obj.get("title", title).replace(" ", "")
result.append(f"class {obj_title}(TypedDict{total}):") typed_dict = [f"class {obj_title}(TypedDict{total}):"]
for key, value in obj_properties.items(): for key, value in obj_properties.items():
extras, param_annotation = generate_typed_dicts_from_json_schema( extras, param_annotation = generate_typed_dicts_from_json_schema(
@ -130,7 +130,7 @@ def generate_typed_dicts_from_json_schema(
param_annotation = f"NotRequired[{param_annotation}]" param_annotation = f"NotRequired[{param_annotation}]"
if not no_comments: if not no_comments:
result.extend( typed_dict.extend(
[ [
f" # Format: {fmt}" if (fmt := value.get("format")) else "", f" # Format: {fmt}" if (fmt := value.get("format")) else "",
f" # Example: {', '.join(str(ex) for ex in exs)}" f" # Example: {', '.join(str(ex) for ex in exs)}"
@ -139,7 +139,9 @@ def generate_typed_dicts_from_json_schema(
] ]
) )
result.append(f" {key}: {param_annotation}") typed_dict.append(f" {key}: {param_annotation}")
result.extend(typed_dict)
else: else:
annotation = "dict" annotation = "dict"