Skip to content

refactor: derive camelCase model aliases with an alias generator - #2319

Merged
vdusek merged 3 commits into
v2from
camel-alias-generator
Oct 13, 2026
Merged

vdusek merged 3 commits into
v2from
camel-alias-generator

Conversation

@vdusek

@vdusek vdusek commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Models with camelCase external keys now set alias_generator=to_camel in their model_config, next to the existing validate_by_name/validate_by_alias, so their aliases are derived from the field names. Over 90 hand-written Field(alias=...) entries go away. An explicit alias stays only where the key differs from the generated one, such as crawlerRuntimeMillis, requestId, timeRemainingSecs, sitemapCompleted, the snake_case adaptive statistics fields and session_id.

The wire format doesn't change. A dump of the effective alias of every field and computed field across all 40 models is identical before and after. The only behavioural difference is that CrawleeRequestData now also accepts field names on validation, as the other models already do.

Closes: #1954

✍️ Drafted by Claude Code

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

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v2@672c58b). Learn more about missing BASE report.

Additional details and impacted files
@@          Coverage Diff          @@
##             v2    #2319   +/-   ##
=====================================
  Coverage      ?   94.00%           
=====================================
  Files         ?      183           
  Lines         ?    13570           
  Branches      ?        0           
=====================================
  Hits          ?    12757           
  Misses        ?      813           
  Partials      ?        0           
Flag Coverage Δ
unit 94.00% <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 Mantisus October 13, 2026 13:13
@vdusek
vdusek marked this pull request as ready for review October 13, 2026 13:13
@vdusek
vdusek requested a review from apify-factory October 13, 2026 13:13

@apify-factory apify-factory left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nothing blocking.

@Mantisus Mantisus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@apify-approval-mirror apify-approval-mirror Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mirroring approval from @Mantisus.

@vdusek
vdusek merged commit 413c5c5 into v2 Oct 13, 2026
30 checks passed
@vdusek
vdusek deleted the camel-alias-generator branch October 13, 2026 15:24
vdusek added a commit that referenced this pull request Oct 16, 2026
Models with camelCase external keys now set `alias_generator=to_camel`
in their `model_config`, next to the existing
`validate_by_name`/`validate_by_alias`, so their aliases are derived
from the field names. Over 90 hand-written `Field(alias=...)` entries go
away. An explicit alias stays only where the key differs from the
generated one, such as `crawlerRuntimeMillis`, `requestId`,
`timeRemainingSecs`, `sitemapCompleted`, the snake_case adaptive
statistics fields and `session_id`.

The wire format doesn't change. A dump of the effective alias of every
field and computed field across all 40 models is identical before and
after. The only behavioural difference is that `CrawleeRequestData` now
also accepts field names on validation, as the other models already do.

Closes: #1954

*✍️ 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.

Use alias_generator=to_camel on Pydantic models instead of manual per-field aliases

4 participants