Skip to content

Commit eeabbba

Browse files
authored
fix: Align model names with the renamed OpenAPI schemas (#1098)
The "Regenerate models" workflow failed ([run](https://github.com/apify/apify-client-python/actions/runs/37614017464)) after apify/apify-docs#3044 renamed schemas in the OpenAPI spec. The TypedDict seeds `Request`, `RequestDraftDelete` and `WebhookCreate` were no longer in the generated file. This switches the seeds to the new names (`RequestResource`, `RequestToDelete`, `CreateWebhookRequest`), regenerates the models, and updates every reference in the resource clients, tests and docs to the new model names, e.g. `Actor` -> `ActorResource`, `ActorShort` -> `ActorListItem`, `WebhookCreateDict` -> `CreateWebhookRequestDict`. The full rename table is in apify/apify-docs#3044. Deprecated aliases for the old names will follow in a separate PR. *✍️ Drafted by Claude Code*
1 parent 67a5431 commit eeabbba

45 files changed

Lines changed: 1345 additions & 1330 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.rules.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Docstrings are written on sync clients and **automatically copied** to async cli
7777

7878
`src/apify_client/_models.py` and `src/apify_client/_typeddicts.py` are **auto-generated** — do not edit them manually. Every Pydantic model and TypedDict comes from the OpenAPI spec.
7979

80-
Each input-side TypedDict ships in two casings: snake_case (`RequestDict`) and camelCase (`RequestCamelDict`). The camel variants are synthesized in `scripts/postprocess_generated_models.py` from the Pydantic `Field(alias=...)` map; resource-client signatures union both with the Pydantic model so users can pass either casing without losing type-checker support.
80+
Each input-side TypedDict ships in two casings: snake_case (`RequestResourceDict`) and camelCase (`RequestResourceCamelDict`). The camel variants are synthesized in `scripts/postprocess_generated_models.py` from the Pydantic `Field(alias=...)` map; resource-client signatures union both with the Pydantic model so users can pass either casing without losing type-checker support.
8181

8282
- 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`)
8383
- After generation, `scripts/postprocess_generated_models.py` is run to apply additional fixes

‎docs/02_concepts/12_typed_models.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Date strings are automatically parsed into timezone-aware `datetime.datetime` ob
3838

3939
## URL fields
4040

41-
Fields holding a URL, such as `Run.container_url` or `Dataset.console_url`, are typed as [`AnyUrl`](https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.AnyUrl). Their values are validated and normalized, so the string you read back can differ from the one the API sent. Both forms denote the same URL under [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.3), they're just different strings.
41+
Fields holding a URL, such as `Run.container_url` or `DatasetResource.console_url`, are typed as [`AnyUrl`](https://docs.pydantic.dev/latest/api/networks/#pydantic.networks.AnyUrl). Their values are validated and normalized, so the string you read back can differ from the one the API sent. Both forms denote the same URL under [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.3), they're just different strings.
4242

4343
```python
4444
from pydantic import AnyUrl

‎docs/02_concepts/code/12_typed_models_access_async.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
async def main() -> None:
77
apify_client = ApifyClientAsync(TOKEN)
88

9-
# `get` returns an `Actor` Pydantic model — fields are typed and IDE-completable.
9+
# `get` returns an `ActorResource` Pydantic model with typed, IDE-completable fields.
1010
actor = await apify_client.actor('apify/hello-world').get()
1111
if actor is None:
1212
return

‎docs/02_concepts/code/12_typed_models_access_sync.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def main() -> None:
77
apify_client = ApifyClient(TOKEN)
88

9-
# `get` returns an `Actor` Pydantic model — fields are typed and IDE-completable.
9+
# `get` returns an `ActorResource` Pydantic model with typed, IDE-completable fields.
1010
actor = apify_client.actor('apify/hello-world').get()
1111
if actor is None:
1212
return

‎scripts/postprocess_generated_models.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Keep only the TypedDicts actually used as resource-client method inputs (plus their transitive dependencies).
1616
The file is generated in full by datamodel-codegen; the trimming happens here.
1717
- Rename every kept class to add a `Dict` suffix so it doesn't clash with the Pydantic model name
18-
(e.g. `WebhookCreate` -> `WebhookCreateDict`) and rewire references.
18+
(e.g. `CreateWebhookRequest` -> `CreateWebhookRequestDict`) and rewire references.
1919
- Generate a camelCase sibling for every kept TypedDict (`FooDict` -> `FooCamelDict`) so users can pass API-shaped
2020
dicts and still satisfy the type checker. Field identifiers are looked up in the Pydantic alias map extracted
2121
from `_models.py`; nested TypedDict refs are rewired to the camel variant.
@@ -55,11 +55,11 @@
5555
# union is introduced on a resource-client method signature.
5656
RESOURCE_INPUT_TYPEDDICTS: frozenset[str] = frozenset(
5757
{
58-
'Request', # RequestQueueClient.update_request
58+
'RequestResource', # RequestQueueClient.update_request
5959
'RequestWithoutId', # RequestQueueClient.add_request, batch_add_requests
60-
'RequestDraftDelete', # RequestQueueClient.batch_delete_requests
60+
'RequestToDelete', # RequestQueueClient.batch_delete_requests
6161
'TaskInput', # Actor/Task start/call/update default input
62-
'WebhookCreate', # Actor/Task start/call webhook list element
62+
'CreateWebhookRequest', # Actor/Task start/call webhook list element
6363
'WebhookRepresentation', # Actor/Task start/call ad-hoc webhook list element
6464
}
6565
)
@@ -497,7 +497,7 @@ def build_alias_map(models_source: str) -> dict[str, dict[str, str]]:
497497

498498

499499
def _camel_dict_name(snake_name: str) -> str:
500-
"""Insert `Camel` before the trailing `Dict` (e.g. `RequestDict` -> `RequestCamelDict`)."""
500+
"""Insert `Camel` before the trailing `Dict` (e.g. `RequestResourceDict` -> `RequestResourceCamelDict`)."""
501501
if not snake_name.endswith('Dict'):
502502
raise ValueError(f"Expected name to end with 'Dict': {snake_name!r}")
503503
return snake_name[: -len('Dict')] + 'CamelDict'
@@ -575,7 +575,7 @@ def add_camel_case_typeddicts(content: str, alias_map: dict[str, dict[str, str]]
575575
for node in tree.body:
576576
if isinstance(node, ast.ClassDef):
577577
# Every class kept in `_typeddicts.py` is a TypedDict — either directly (base is `TypedDict`) or by
578-
# inheriting from a sibling TypedDict (e.g. `RequestDict(RequestBaseDict)`). The `Dict` suffix
578+
# inheriting from a sibling TypedDict (e.g. `RequestResourceDict(RequestBaseDict)`). The `Dict` suffix
579579
# is the load-bearing filter; the base check is informational only.
580580
if not node.name.endswith('Dict') or node.name.endswith('CamelDict'):
581581
continue

0 commit comments

Comments
 (0)