Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/manual_regenerate_models.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow regenerates Pydantic models (src/apify_client/_models.py) from the OpenAPI spec.
# This workflow regenerates Pydantic models and TypedDicts (src/apify_client/_generated/) from the OpenAPI spec.
#
# It can be triggered in two ways:
# 1. Automatically via workflow_dispatch from the apify-docs CI pipeline (with docs_pr_number and docs_workflow_run_id).
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
id: commit
uses: EndBug/add-and-commit@v10
with:
add: src/apify_client/_models.py
add: 'src/apify_client/_generated/*.py'
author_name: apify-service-account
author_email: apify-service-account@users.noreply.github.com
message: ${{ env.TITLE }}
Expand All @@ -130,9 +130,9 @@ jobs:
else
if [[ -n "$DOCS_PR_NUMBER" ]]; then
DOCS_PR_URL="https://github.com/apify/apify-docs/pull/${DOCS_PR_NUMBER}"
BODY="This PR updates the auto-generated Pydantic models based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
BODY="This PR updates the auto-generated Pydantic models and TypedDicts based on OpenAPI specification changes in [apify-docs PR #${DOCS_PR_NUMBER}](${DOCS_PR_URL})."
else
BODY="This PR updates the auto-generated Pydantic models from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
BODY="This PR updates the auto-generated Pydantic models and TypedDicts from the [published OpenAPI specification](https://docs.apify.com/api/openapi.json)."
fi

PR_URL=$(gh pr create \
Expand Down
4 changes: 2 additions & 2 deletions .rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ uv run poe type-check # Run ty type checker
uv run poe unit-tests # Run unit tests
uv run poe check-docstrings # Verify async docstrings match sync
uv run poe fix-docstrings # Auto-fix async docstrings
uv run poe generate-models # Regenerate _models.py from live OpenAPI spec
uv run poe generate-models # Regenerate _generated/_models.py and _generated/_typeddicts.py from live OpenAPI spec
uv run poe generate-models-from-file <path> # Regenerate from a local OpenAPI spec file

# Run a single test
Expand Down Expand Up @@ -73,7 +73,7 @@ Docstrings are written on sync clients and **automatically copied** to async cli

### Data Models

`src/apify_client/_models.py` is **auto-generated** — do not edit it manually.
Files under `src/apify_client/_generated/` (`_models.py`, `_typeddicts.py`) are **auto-generated** — do not edit them manually. The top-level `src/apify_client/_models.py` and `src/apify_client/_typeddicts.py` are stable shim modules that re-export from `_generated/`; they are the public import paths and are hand-maintained.

- Generated by `datamodel-code-generator` from the OpenAPI spec at `https://docs.apify.com/api/openapi.json` (config in `pyproject.toml` under `[tool.datamodel-codegen]`, aliases in `datamodel_codegen_aliases.json`)
- After generation, `scripts/postprocess_generated_models.py` is run to apply additional fixes
Expand Down
22 changes: 18 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ indent-style = "space"
"**/docs/03_guides/code/05_custom_http_client_{async,sync}.py" = [
"ARG002", # Unused method argument
]
"src/apify_client/_models.py" = [
"src/apify_client/_generated/*.py" = [
"D", # Everything from the pydocstyle
"E501", # Line too long
"ERA001", # Commented-out code
Expand Down Expand Up @@ -210,7 +210,7 @@ context = 7
# https://koxudaxi.github.io/datamodel-code-generator/
[tool.datamodel-codegen]
input_file_type = "openapi"
output = "src/apify_client/_models.py"
output = "src/apify_client/_generated/_models.py"
target_python_version = "3.11"
output_model_type = "pydantic_v2.BaseModel"
use_schema_description = true
Expand Down Expand Up @@ -272,8 +272,22 @@ shell = "./build_api_reference.sh && corepack enable && yarn && uv run yarn star
cwd = "website"

[tool.poe.tasks.generate-models]
shell = "uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json && python scripts/postprocess_generated_models.py"
shell = """
uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json \
&& uv run datamodel-codegen --url https://docs.apify.com/api/openapi.json \
--output src/apify_client/_generated/_typeddicts.py \
--output-model-type typing.TypedDict \
--no-use-closed-typed-dict \
&& python scripts/postprocess_generated_models.py
"""

[tool.poe.tasks.generate-models-from-file]
shell = "uv run datamodel-codegen --input $input_file && python scripts/postprocess_generated_models.py"
shell = """
uv run datamodel-codegen --input $input_file \
&& uv run datamodel-codegen --input $input_file \
--output src/apify_client/_generated/_typeddicts.py \
--output-model-type typing.TypedDict \
--no-use-closed-typed-dict \
&& python scripts/postprocess_generated_models.py
"""
args = [{ name = "input-file", positional = true, required = true }]
Loading
Loading