diff --git a/docs/usage/rest-api.md b/docs/usage/rest-api.md index 273fb614b..80e788ece 100644 --- a/docs/usage/rest-api.md +++ b/docs/usage/rest-api.md @@ -217,6 +217,40 @@ resp: Response[FullRepository] = github.rest.repos.get("owner", "repo") repo: dict[str, Any] = resp.json() ``` +=== "Pydantic v1" + + If you have already got the parsed data and want to dump it into a dict object or JSON string, you can use the pydantic model's `dict` or `json` method: + + ```python hl_lines="8-9" + from typing import Any + from githubkit import Response + from githubkit.versions.latest.models import FullRepository + + resp: Response[FullRepository] = github.rest.repos.get("owner", "repo") + repo: FullRepository = resp.parsed_data + + repo_dict: dict[str, Any] = repo.dict(by_alias=True, exclude_unset=True) + repo_json: str = repo.json(by_alias=True, exclude_unset=True) + ``` + +=== "Pydantic v2" + + If you have already got the parsed data and want to dump it into a dict object or JSON string, you can use the pydantic model's `model_dump` or `model_dump_json` method: + + ```python hl_lines="8-11" + from typing import Any + from githubkit import Response + from githubkit.versions.latest.models import FullRepository + + resp: Response[FullRepository] = github.rest.repos.get("owner", "repo") + repo: FullRepository = resp.parsed_data + + repo_dict: dict[str, Any] = repo.model_dump( + mode="json", by_alias=True, exclude_unset=True + ) + repo_json: str = repo.model_dump_json(by_alias=True, exclude_unset=True) + ``` + ## REST API Versioning githubkit supports multiple versions of GitHub API, you can switch between versions as follows: