Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

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:

  • Understand the issue and existing code

    • PR Rename from "top" to "maxCount" in paging operations #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
  • 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
  • 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)
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
Original prompt

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)


💡 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 in the docs.

…xCount

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Feb 9, 2026
Copilot AI and others added 3 commits February 9, 2026 16:20
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft
Copy link
Contributor

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 9, 2026

@copilot update https://github.com/microsoft/typespec/blob/main/packages/http-client-csharp/generator/docs/backward-compatibility.md with this scenario

Updated the backward compatibility documentation with a new section covering the top to maxCount parameter conversion scenario. The documentation now includes:

  • A new subsection "Top Parameter Conversion to MaxCount" under "Parameter Name Casing"
  • Case 1: When top exists in LastContractView, it's preserved for backward compatibility
  • Case 2: When top doesn't exist in LastContractView, it's converted to maxCount for standardization
  • Code examples for both cases showing the behavior

Commit: 1309792

@JoshLove-msft
Copy link
Contributor

  • "Parameter Name Casing"

@copilot we need to change this to Parameter Naming since it contains scenarios that are not about casing.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 9, 2026

  • "Parameter Name Casing"

@copilot we need to change this to Parameter Naming since it contains scenarios that are not about casing.

Renamed the section from "Parameter Name Casing" to "Parameter Naming" in both the table of contents and section heading. Also updated the section description to reflect that it covers parameter name corrections, standardization, and conversions to follow naming conventions.

Commit: 9e29f22

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

No changes needing a change description found.

@JoshLove-msft JoshLove-msft added this pull request to the merge queue Feb 9, 2026
Merged via the queue into main with commit 3dca795 Feb 9, 2026
23 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/enable-backcompat-support-top-parameter-again branch February 9, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable backcompat support for top parameter

3 participants