Skip to content

fix: relax enum validation to tolerate unknown API values - #941

Merged
vdusek merged 1 commit into
masterfrom
fix/relax-enum-validation
Jul 10, 2026
Merged

fix: relax enum validation to tolerate unknown API values#941
vdusek merged 1 commit into
masterfrom
fix/relax-enum-validation

Conversation

@vdusek

@vdusek vdusek commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Enum fields in the generated models were strict Literal[...] aliases in _literals.py. Because every API response is Pydantic-validated, any unknown or newly introduced enum value the platform sent raised a ValidationError and broke the whole call.

The postprocess step now emits an open literal Literal[...] | str for each shared enum alias, so unknown values validate while the known members stay as autocomplete hints. Discriminated unions are unaffected — they use inline single-value Literal[...], not the shared aliases.

Changes:

  • scripts/postprocess_generated_models.py: emit Literal[...] | str; broaden the literal-alias detection (_is_literal_expr) so a widened alias is still recognized and moved into _literals.py.
  • src/apify_client/_literals.py: regenerated — all 11 aliases widened (members unchanged).
  • pyproject.toml: ignore PYI051 for _literals.py (the redundant-looking Literal[...] | str union is deliberate).
  • tests/unit/test_postprocess_generated_models.py: cover the open union end-to-end, plus a negative case for non-str unions.

Closes #931

@vdusek vdusek added the t-tooling Issues with this label are in the ownership of the tooling team. label Jul 10, 2026
@vdusek vdusek self-assigned this Jul 10, 2026
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.54%. Comparing base (68c0e24) to head (113a862).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #941      +/-   ##
==========================================
- Coverage   94.56%   94.54%   -0.02%     
==========================================
  Files          48       48              
  Lines        5119     5119              
==========================================
- Hits         4841     4840       -1     
- Misses        278      279       +1     
Flag Coverage Δ
integration 92.71% <100.00%> (-0.32%) ⬇️
unit 83.43% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek
vdusek requested a review from Pijukatel July 10, 2026 07:37
@vdusek
vdusek marked this pull request as ready for review July 10, 2026 07:37
@vdusek
vdusek merged commit 587baa7 into master Jul 10, 2026
30 checks passed
@vdusek
vdusek deleted the fix/relax-enum-validation branch July 10, 2026 09:39
vdusek added a commit that referenced this pull request Aug 3, 2026
)

Replaces the apify-docs-triggered model regeneration with a nightly job,
and records which published OpenAPI specification the generated models
came from.

## What changes

- **`on_schedule_regenerate_models.yaml`** - nightly at 02:00 UTC plus
manual dispatch. Regenerates on master and opens a pull request when the
models change. `manual_regenerate_models.yaml` is deleted.
- **`scripts/openapi_spec.py`** - downloads and validates the published
specification into git-ignored `tmp/` (both codegen passes read that one
copy), then records its `info.version` in `pyproject.toml` under
`[tool.apify.openapi-spec]`. The specification itself is not committed.
- **`_models.py`** loses the `Plan.available_proxy_groups` docstring -
accumulated codegen drift from the `datamodel-code-generator` bumps
(#968, #975), not a specification change.

## Why

The old workflow was dispatched by apify-docs and checked out a
permanent, never-rebased branch *before* regenerating, so it generated
with that branch's stale tooling. In #979 that produced `_literals.py`
in the pre-#941 closed `Literal[...]` form; merging it would have
silently reverted the enum relaxation. It also opened with a `TODO`
title that blocked `pr-title-check` - a design that needs human action
to become mergeable, which is what let #979 rot for 20 days while the
same spec changes were landed by hand (#923, #936, #947, #960, #974).

The nightly job always generates on master and rebuilds its
`ci/regenerate-models` branch from master instead of appending, so the
diff is always "current spec vs current master" and can't resurrect a
stale generated file. It opens with a mergeable `chore:` title;
reviewers retitle to `fix:`/`feat:` when the diff is user-facing.

## Notes

- **Merge apify/apify-docs#2835 first** - it removes the dispatch that
still calls the workflow deleted here.
- **Needs a `SLACK_WEBHOOK_URL` repository secret** for the failure
alert.
- The recorded version is a coarse marker, not a content identity:
apify-docs bumps `components/version.yaml` in a follow-up `[skip ci]`
commit, so a deploy can publish new content under the old stamp. A moved
value proves the specification changed; an unchanged one proves nothing.

*✍️ Drafted by Claude Code*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relax enum validation in generated models to tolerate unknown/new API values

3 participants