Commit 8ff8ec7
authored
chore: use alias_generator on generated models instead of per-field aliases (#858)
The codegen postprocess now adds `alias_generator=to_camel` to every
model's `ConfigDict` and emits an explicit `Field(alias=...)` only where
the camelCase conversion is irregular (all-caps usage keys,
`gitHubGistUrl`, `schema`, ...). This drops the explicit per-field
aliases in `_models.py` from 623 to 45 and shrinks the file from 3852 to
3077 lines.
The wire format is unchanged, guarded by tests: Pydantic lets an
explicit alias override the generator, and `populate_by_name=True` keeps
snake_case input working. The before/after runtime alias contract is
byte-identical across all 212 models / 1060 fields, and `_typeddicts.py`
/ `_literals.py` regenerate unchanged (the camel `*Dict` synthesis now
derives names via `to_camel` plus the irregular-alias overrides).
datamodel-codegen has no native option for this (its `--no-alias` would
drop the irregular aliases too), so the work lives in
`scripts/postprocess_generated_models.py`.
Closes #8521 parent 8dffe34 commit 8ff8ec7
5 files changed
Lines changed: 886 additions & 751 deletions
File tree
- scripts
- src/apify_client
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
| 298 | + | |
| 299 | + | |
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
| 303 | + | |
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
| |||
308 | 311 | | |
309 | 312 | | |
310 | 313 | | |
| 314 | + | |
311 | 315 | | |
312 | 316 | | |
313 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
412 | 414 | | |
413 | 415 | | |
414 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
415 | 441 | | |
416 | 442 | | |
417 | 443 | | |
418 | | - | |
419 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
420 | 447 | | |
| 448 | + | |
421 | 449 | | |
422 | 450 | | |
423 | 451 | | |
424 | 452 | | |
425 | 453 | | |
426 | 454 | | |
427 | 455 | | |
428 | | - | |
429 | | - | |
430 | 456 | | |
| 457 | + | |
431 | 458 | | |
432 | 459 | | |
433 | | - | |
434 | | - | |
435 | | - | |
| 460 | + | |
| 461 | + | |
436 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
437 | 469 | | |
438 | 470 | | |
439 | 471 | | |
| |||
0 commit comments