Commit 1a6fa27
fix(client): emit typed enum for const/enum on parameter schemas
PR #12 fixed string `const` inside schema components, but the parameter
pipeline is a separate code path: a path/query parameter declared with
`{ "type": "string", "const": "X" }` (or `enum: [...]`) on its inline
schema still generated `impl AsRef<str>`, letting callers pass any value
even though only one (or a fixed set) is valid.
Extend `ParameterInfo` with `enum_values` and detect the string-enum
case in `analyze_parameter`. The client generator emits a synthetic
inline enum (`<OperationId><ParamName>`) with `Display`, `AsRef<str>`,
and an `as_str()` helper, plus serde rename attrs. The existing
path/query templating uses `format!("{}", v)` / `v.to_string()` for
non-`String` rust_types, so Display makes it work without call-site
changes.
The same code path also fixes explicit `enum: [...]` on parameter
schemas, which was previously generated as `impl AsRef<str>` too.
`enum_values` uses `skip_serializing_if = "Option::is_none"` so existing
parameter snapshots are unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3e93ad3 commit 1a6fa27
4 files changed
Lines changed: 319 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
| |||
3634 | 3641 | | |
3635 | 3642 | | |
3636 | 3643 | | |
3637 | | - | |
| 3644 | + | |
3638 | 3645 | | |
3639 | 3646 | | |
3640 | 3647 | | |
| |||
3649 | 3656 | | |
3650 | 3657 | | |
3651 | 3658 | | |
3652 | | - | |
| 3659 | + | |
3653 | 3660 | | |
3654 | 3661 | | |
3655 | 3662 | | |
| |||
3740 | 3747 | | |
3741 | 3748 | | |
3742 | 3749 | | |
3743 | | - | |
| 3750 | + | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
| 3754 | + | |
| 3755 | + | |
3744 | 3756 | | |
3745 | 3757 | | |
3746 | 3758 | | |
| 3759 | + | |
3747 | 3760 | | |
| 3761 | + | |
| 3762 | + | |
3748 | 3763 | | |
3749 | 3764 | | |
3750 | 3765 | | |
3751 | 3766 | | |
3752 | 3767 | | |
3753 | 3768 | | |
| 3769 | + | |
3754 | 3770 | | |
3755 | 3771 | | |
3756 | 3772 | | |
| |||
3764 | 3780 | | |
3765 | 3781 | | |
3766 | 3782 | | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
| 3790 | + | |
| 3791 | + | |
| 3792 | + | |
| 3793 | + | |
| 3794 | + | |
| 3795 | + | |
| 3796 | + | |
3767 | 3797 | | |
3768 | 3798 | | |
3769 | 3799 | | |
| |||
3774 | 3804 | | |
3775 | 3805 | | |
3776 | 3806 | | |
| 3807 | + | |
3777 | 3808 | | |
3778 | 3809 | | |
3779 | 3810 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
| 378 | + | |
| 379 | + | |
377 | 380 | | |
378 | 381 | | |
379 | 382 | | |
| |||
387 | 390 | | |
388 | 391 | | |
389 | 392 | | |
| 393 | + | |
| 394 | + | |
390 | 395 | | |
391 | 396 | | |
392 | 397 | | |
| |||
395 | 400 | | |
396 | 401 | | |
397 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 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 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
398 | 489 | | |
399 | 490 | | |
400 | 491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1432 | 1432 | | |
1433 | 1433 | | |
1434 | 1434 | | |
1435 | | - | |
| 1435 | + | |
1436 | 1436 | | |
1437 | 1437 | | |
1438 | 1438 | | |
| |||
0 commit comments