Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add support for REST-API-VERSION based on the used schema #24

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def build_rest_api(data: OpenAPIData, config: Config):
for tag, endpoints in data.endpoints_by_tag.items():
logger.info(f"Building endpoints for tag {tag}...")
tag_path = client_path / f"{tag}.py"
tag_path.write_text(client_template.render(tag=tag, endpoints=endpoints))
tag_path.write_text(
client_template.render(
tag=tag, endpoints=endpoints, rest_api_version=config.rest_api_version
)
)
logger.info(f"Successfully built endpoints for tag {tag}!")
logger.info("Successfully built endpoints!")

Expand Down
1 change: 1 addition & 0 deletions codegen/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class Config(BaseModel):
rest_description_source: str
rest_api_version: str
webhook_schema_source: str
class_overrides: Dict[str, str] = {}
field_overrides: Dict[str, str] = {}
Expand Down
4 changes: 3 additions & 1 deletion codegen/templates/client/_request.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ params=exclude_unset(params),
{{ name }}=exclude_unset({{ name }}),
{% endif %}
{% if endpoint.header_params %}
headers=exclude_unset(headers),
headers=exclude_unset({**headers, "X-GitHub-Api-Version": self._REST_API_VERSION}),
{% else %}
headers={"X-GitHub-Api-Version": self._REST_API_VERSION},
{% endif %}
{% if endpoint.cookie_params %}
cookies=exclude_unset(cookies),
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/client/client.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ if TYPE_CHECKING:
from githubkit.response import Response

class {{ pascal_case(tag) }}Client:
_REST_API_VERSION = "{{ rest_api_version }}"

def __init__(self, github: "GitHubCore"):
self._github = github

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ reportPrivateImportUsage = false
reportShadowedImports = false

[tool.codegen]
rest-description-source = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.json"
rest-description-source = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.2022-11-28.json"
rest-api-version = "2022-11-28"
webhook-schema-source = "https://unpkg.com/@octokit/webhooks-schemas/schema.json"
client-output = "githubkit/rest/"
webhooks-output = "githubkit/webhooks/models.py"
Expand Down