Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

Model Factory Parameter Naming Fix: eTagetag

Problem

Model factory methods in Azure Management SDKs were generating parameter names that don't follow .NET naming conventions for acronyms. Specifically, the ETag property was being converted to eTag instead of the correct etag in camelCase parameter names.

Solution

Implemented a property-to-parameter name mapping in ModelFactoryVisitor.cs that specifically handles the ETag property case:

  • Added a static dictionary mapping "ETag" property name to "etag" parameter name
  • When processing model factory methods, the visitor checks each parameter's associated property
  • If the property name matches an entry in the dictionary and the parameter name differs, the parameter is updated
  • XML documentation is automatically refreshed by updating the method signature
  • This approach allows for precise control over specific property-to-parameter name mappings

Changes Made

  • Reverted previous StringExtensions.cs approach per feedback
  • Reverted ArmDeviceRegistryModelFactory.cs manual changes per feedback
  • Implemented dictionary-based mapping in ModelFactoryVisitor.cs
  • Simplified XML doc update to use signature refresh pattern (same as NameVisitor.cs)
  • Added etag property to Mgmt-TypeSpec test project FooProperties model
  • Regenerated test project verifying etag parameter is correctly generated
  • Merged latest main branch and resolved conflicts (multiple times)
  • Updated TypeSpec property name to lowercase per review feedback
  • Optimized to avoid unnecessary updates when parameter name is already correct
  • All generator tests pass (60/60)

Test Verification

Added Azure.Core.eTag property (lowercase) to the Mgmt-TypeSpec test project. The generated model factory now correctly shows:

/// <param name="etag"> ETag property for testing etag parameter name generation. </param>
public static FooData FooData(..., ETag? etag = default)

Files Modified

  • eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Visitors/ModelFactoryVisitor.cs - Added parameter name mapping logic with optimized update check
  • eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp - Added etag property (lowercase) for testing
  • Generated test files updated to demonstrate the fix
  • Merged latest changes from main branch

Fixes #53476

Original prompt

This section details on the original issue you should resolve

<issue_title>model factory parameter should use etag instead of eTag</issue_title>
<issue_description>Image</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #53476


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 24, 2025 08:05
Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
…eter

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix model factory parameter to use etag instead of eTag Fix model factory parameter naming: change eTag to etag for acronym compliance Oct 24, 2025
Copilot AI requested a review from live1206 October 24, 2025 08:12
Copilot finished work on behalf of live1206 October 24, 2025 08:12
…st property

- Revert StringExtensions.cs changes as requested
- Revert ArmDeviceRegistryModelFactory.cs manual changes
- Implement ETag parameter name mapping in ModelFactoryVisitor.cs using a dictionary
- Add ETag property to Mgmt-TypeSpec test project to verify the fix
- Remove StringExtensionsTests.cs as it's no longer needed
- Regenerate test project showing etag parameter working correctly

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot finished work on behalf of live1206 October 27, 2025 03:06
Copilot AI requested a review from live1206 October 27, 2025 03:06
@live1206
Copy link
Member

@copilot merge from latest main branch, resolve the conflict and regenerate the test code

- Instead of manually constructing XmlDocParamStatement objects, use method.Update(signature: method.Signature) to refresh documentation
- This is the same pattern used in NameVisitor.cs and is cleaner/simpler
- All tests pass (60/60) and generated code still correctly shows etag parameter

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 October 27, 2025 03:19
Copilot finished work on behalf of live1206 October 27, 2025 03:19
Copilot AI and others added 2 commits October 27, 2025 03:23
…tory-etag-parameter

# Conflicts:
#	eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json
- Merged latest main branch into the PR branch
- Resolved merge conflict in tspCodeModel.json
- Regenerated test project to ensure compatibility
- All generator tests pass (60/60)
- Fix verified: etag parameter still correctly generated

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 27, 2025

@copilot merge from latest main branch, resolve the conflict and regenerate the test code

Done. Merged from latest main branch, resolved the tspCodeModel.json conflict, and regenerated the test code. All tests pass (60/60) and the etag parameter fix is still working correctly. (commits d095981 and 4daefd3)

Copilot finished work on behalf of live1206 October 27, 2025 03:28
- Changed property name in foo.tsp from eTag to etag (lowercase)
- Regenerated test project with updated property name
- Model factory still correctly generates etag parameter (lowercase)
- All generator tests pass (60/60)

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot AI requested a review from live1206 October 27, 2025 06:18
Copilot finished work on behalf of live1206 October 27, 2025 06:18
@live1206 live1206 marked this pull request as ready for review October 27, 2025 06:23
Copilot AI review requested due to automatic review settings October 27, 2025 06:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes model factory parameter naming to comply with .NET acronym conventions by changing eTag to etag in camelCase parameter names. The solution implements a property-to-parameter name mapping in ModelFactoryVisitor.cs that specifically handles the ETag property case, ensuring the generated parameter name follows the correct convention.

Key Changes:

  • Added dictionary-based property-to-parameter name mapping in ModelFactoryVisitor
  • Added test case with lowercase etag property in TypeSpec test project
  • Method signature update automatically refreshes XML documentation

Reviewed Changes

Copilot reviewed 2 out of 7 changed files in this pull request and generated 1 comment.

File Description
ModelFactoryVisitor.cs Implements property-to-parameter name mapping with dictionary and parameter name update logic
foo.tsp Adds lowercase etag property to test the parameter name generation

- Added check to compare parameter.Name with newName before updating
- Combined the property check, dictionary lookup, and name comparison into a single if condition
- Avoids unnecessary parameter updates when the name is already correct
- All tests pass (60/60) and generated code verified

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copilot finished work on behalf of live1206 October 27, 2025 06:53
@live1206
Copy link
Member

/check-enforcer override

@live1206
Copy link
Member

@copilot Merge from latest main and regenerate test

Copilot AI and others added 2 commits October 29, 2025 08:51
…tory-etag-parameter

# Conflicts:
#	eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json
- Merged latest main branch into the PR branch
- Resolved merge conflict in tspCodeModel.json
- Regenerated test project to ensure compatibility
- All generator tests pass (60/60)
- Fix verified: etag parameter still correctly generated

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot Merge from latest main and regenerate test

Done. Merged from latest main branch, resolved the tspCodeModel.json conflict, and regenerated the test. All tests pass (60/60) and the etag parameter fix is still working correctly. (commits 36a5ed1 and 4d52e45)

Copilot finished work on behalf of live1206 October 29, 2025 08:57
@live1206
Copy link
Member

/check-enforcer override

@live1206 live1206 enabled auto-merge (squash) October 29, 2025 09:16
@live1206 live1206 merged commit 1962463 into main Oct 29, 2025
22 checks passed
@live1206 live1206 deleted the copilot/fix-model-factory-etag-parameter branch October 29, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

model factory parameter should use etag instead of eTag

4 participants