Commit 3dca795
Add backcompat support for top parameter (#9645)
## Plan: Add backward compatibility support for `top` parameter
conversion
Based on PR #9505 which added conversion from `top` to `maxCount`,
implement similar backward compatibility as was done for `maxPageSize`
recasing.
### Changes Required:
- [x] Understand the issue and existing code
- PR #9505 added conversion from "top" to "maxCount" in
RestClientProvider.cs (lines 1016-1021)
- Similar backward compatibility exists for "maxPageSize" using
GetCorrectedPageSizeName (lines 874-895)
- Need to add similar backward compatibility for "top" parameter
- [x] Implement backward compatibility for top parameter
- Created reusable `GetCorrectedParameterName` helper method that takes
originalName, updatedName, and client
- Both paging parameter corrections (page size and maxCount) call this
helper directly
- Preserves parameter name if it exists in previous version
(LastContractView)
- Applies normalization or conversion if no backward compatibility
needed
- Consolidated both parameter corrections under single
InputPagingServiceMethod check
- Made updatedName parameter non-nullable since it's always provided by
callers
- Moved page size normalization logic inside the parameter match check
for efficiency
- [x] Add/update tests
- Updated test `TopParameterPreservedWhenExistsInLastContractView` to
validate LastContractView scenario
- Created test data file representing previous contract with "top"
parameter
- Test validates that "top" is preserved when it exists in
LastContractView
- All 6 tests passing including test for "top" to "maxCount" conversion
when no LastContractView
- All PageSizeParameter tests pass (6/6)
- [x] Run tests and validate changes
- Successfully built C# client generator
- All ListPageableTests pass (6/6)
- All PageSizeParameter tests pass (6/6)
- Verified backward compatibility scenario works correctly
- Verified no breaking changes for existing code
- [x] Update documentation
- Updated backward-compatibility.md with the new top parameter
conversion scenario
- Added Table of Contents entries for the new subsection
- Documented both backward compatibility case (preserves "top") and
standardization case (converts to "maxCount")
- Renamed "Parameter Name Casing" to "Parameter Naming" to better
reflect the section content
- [x] Refactor to eliminate code duplication
- Created single reusable `GetCorrectedParameterName` helper method
- Removed wrapper methods `GetCorrectedPageSizeName` and
`GetCorrectedMaxCountName`
- Both paging parameters now call the helper directly with appropriate
arguments
- Maintains same functionality with minimal, maintainable code
- [x] Improve code organization
- Consolidated paging parameter name corrections under single
InputPagingServiceMethod check
- Split out specific parameter name matching into separate if blocks
within
- Improved readability and maintainability
- [x] Simplify method signature
- Made updatedName parameter non-nullable since all callers provide
non-null values
- Removed unnecessary null coalesce operator
- Simplified return statement and comment
- [x] Optimize parameter name correction logic
- Moved page size normalization check inside the parameter match
condition
- Only performs normalization when actually needed (when we find a
matching parameter)
- More efficient as it avoids unnecessary work on every method call
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Enable backcompat support for `top`
parameter</issue_title>
> <issue_description>#9505
added a conversion from top to maxCount. We should add similar back
compat support as we added for the `maxPageSize`
recasing.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #9643
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: jolov <jolov@microsoft.com>1 parent 7bf4831 commit 3dca795
File tree
4 files changed
+221
-29
lines changed- packages/http-client-csharp/generator
- Microsoft.TypeSpec.Generator.ClientModel
- src/Providers
- test/Providers/CollectionResultDefinitions
- TestData/ListPageableTests/TopParameterPreservedWhenExistsInLastContractView
- docs
4 files changed
+221
-29
lines changedLines changed: 23 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
871 | 871 | | |
872 | 872 | | |
873 | 873 | | |
874 | | - | |
| 874 | + | |
875 | 875 | | |
876 | | - | |
| 876 | + | |
877 | 877 | | |
878 | 878 | | |
879 | | - | |
| 879 | + | |
880 | 880 | | |
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
884 | | - | |
| 884 | + | |
| 885 | + | |
885 | 886 | | |
886 | 887 | | |
887 | | - | |
888 | | - | |
| 888 | + | |
| 889 | + | |
889 | 890 | | |
890 | | - | |
| 891 | + | |
891 | 892 | | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | 893 | | |
896 | 894 | | |
897 | 895 | | |
| |||
962 | 960 | | |
963 | 961 | | |
964 | 962 | | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | 963 | | |
972 | 964 | | |
973 | 965 | | |
| |||
1013 | 1005 | | |
1014 | 1006 | | |
1015 | 1007 | | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
| 1008 | + | |
| 1009 | + | |
1019 | 1010 | | |
1020 | | - | |
1021 | | - | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
1022 | 1016 | | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
| 1017 | + | |
| 1018 | + | |
1027 | 1019 | | |
1028 | | - | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
1029 | 1026 | | |
1030 | 1027 | | |
1031 | 1028 | | |
| |||
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
72 | 137 | | |
73 | 138 | | |
74 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
Lines changed: 118 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
361 | 363 | | |
362 | 364 | | |
363 | 365 | | |
364 | | - | |
| 366 | + | |
365 | 367 | | |
366 | | - | |
| 368 | + | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
| |||
475 | 477 | | |
476 | 478 | | |
477 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
0 commit comments