Skip to content

Commit 9626ed8

Browse files
authored
💡 Docs: add more info to rest api methods' docstring (#210)
1 parent fdc6515 commit 9626ed8

5 files changed

Lines changed: 20 additions & 17 deletions

File tree

codegen/pyproject.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,3 @@ target-version = "py310"
55

66
[tool.ruff.lint]
77
ignore = ["TID"]
8-
9-
[tool.pyright]
10-
typeCheckingMode = "standard"
11-
reportPrivateImportUsage = false
12-
reportShadowedImports = false
13-
disableBytesTypePromotions = true
14-
15-
pythonVersion = "3.10"
16-
pythonPlatform = "All"
17-
defineConstant = { PYDANTIC_V2 = true }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% macro build_docstring(endpoint) %}
2+
"""{% if endpoint.deprecated %}DEPRECATED {% endif %}{% if endpoint.operation_id %}{{ endpoint.operation_id }}
3+
{% endif %}
4+
5+
{{ endpoint.method | upper }} {{ endpoint.path }}
6+
{% if endpoint.description %}
7+
8+
{{ endpoint.description }}
9+
{% endif %}
10+
{% if endpoint.external_docs %}
11+
12+
See also: {{ endpoint.external_docs }}
13+
{% endif %}
14+
"""
15+
{% endmacro %}

codegen/templates/rest/client.py.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{% from "rest/_param.py.jinja" import endpoint_params, endpoint_raw_params, endpoint_model_params %}
66
{% from "rest/_response.py.jinja" import build_response_type %}
77
{% from "rest/_request.py.jinja" import build_request, build_request_params %}
8+
{% from "rest/_docstring.py.jinja" import build_docstring %}
89

910
from __future__ import annotations
1011

@@ -98,10 +99,8 @@ class {{ pascal_case(tag) }}Client:
9899
self,
99100
{{ endpoint_params(endpoint) | indent(8) }}
100101
) -> {{ build_response_type(endpoint.success_response) }}:
101-
{% if endpoint.external_docs %}
102-
"""See also: {{ endpoint.external_docs }}"""
102+
{{ build_docstring(endpoint) | indent(8) }}
103103

104-
{% endif %}
105104
{{ build_request(endpoint) | indent(8) }}
106105
return self._github.request(
107106
{{ build_request_params(endpoint) | indent(12) }}
@@ -131,10 +130,8 @@ class {{ pascal_case(tag) }}Client:
131130
self,
132131
{{ endpoint_params(endpoint) | indent(8) }}
133132
) -> {{ build_response_type(endpoint.success_response) }}:
134-
{% if endpoint.external_docs %}
135-
"""See also: {{ endpoint.external_docs }}"""
133+
{{ build_docstring(endpoint) | indent(8) }}
136134

137-
{% endif %}
138135
{{ build_request(endpoint) | indent(8) }}
139136
return await self._github.arequest(
140137
{{ build_request_params(endpoint) | indent(12) }}

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ defineConstant = { PYDANTIC_V2 = true }
140140
executionEnvironments = [
141141
# disable overload check for generated version codes
142142
{ root = "githubkit/versions/", reportOverlappingOverload = false },
143+
{ root = "codegen", pythonVersion = "3.10" },
143144
]
144145

145146
exclude = ["codegen/**"]

scripts/run-codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -e
55
# cd to the root of the project
66
cd "$(dirname "$0")/.."
77

8-
python -m codegen && ruff check --select I --fix --exit-zero . && ruff check --fix --exit-zero . && ruff format .
8+
python -m codegen && ruff check --select I --fix --exit-zero . && ruff check --fix --exit-zero . && ruff format . && ruff check --fix .

0 commit comments

Comments
 (0)