Only use full namespace for API version enum when there are collisions#10108
Only use full namespace for API version enum when there are collisions#10108
Conversation
…lisions Use last namespace segment for api version enum names in multi-service scenarios by default. Fall back to full namespace only when two or more services share the same last namespace segment, avoiding unnecessary prefix noise while still guaranteeing uniqueness. Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
...rp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientOptionsProvider.cs
Outdated
Show resolved
Hide resolved
… naming Re-adds ClientHelper.BuildNameForService and its tests that were removed in PR #10061. Uses BuildNameForService for the non-collision case in both ApiVersionEnumProvider.BuildName() and ClientOptionsProvider.BuildVersionProperties(), falling back to the full namespace only when last segments collide. Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
...rp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientOptionsProvider.cs
Outdated
Show resolved
Hide resolved
...crosoft.TypeSpec.Generator.ClientModel/test/Providers/ClientProviders/ClientProviderTests.cs
Show resolved
Hide resolved
...tor/Microsoft.TypeSpec.Generator/test/Providers/EnumProviders/ApiVersionEnumProviderTests.cs
Show resolved
Hide resolved
|
@copilot we also need to ensure we regenerate all the test projects. |
…ct helpers, add TestData validation - Revert ClientOptionsProvider.BuildVersionProperties() to use full namespace (field names unchanged) - Revert ClientProviderTests assertions to original field names - Move GetLastNamespaceSegment and HasLastSegmentCollision to ClientHelper as shared static helpers - Update ApiVersionEnumProvider.BuildName() to use shared ClientHelper methods - Add TestData golden file validation for collision test - Update test data files: only enum type names change, property/field names stay the same Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Ran Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…enum type, version properties, fields) Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4bb660ba-ec46-42ad-8074-4e13314801b6
Refactored to apply Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot lets update the MultiServiceClient_SameLastSegment_ProducesUniqueVersionEnums test in ClientOptionsProviderTests to add TestData validation. We should not remove the existing assertions in the test
…roducesUniqueVersionEnums Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/d68247ba-74e0-495e-9cd6-961dcb2cd21b
Added TestData golden file validation to |
commit: |
There was a problem hiding this comment.
@copilot lets change the default naming of the ServiceVersion enum in the multiservice client scenario. Instead of ServiceXVersion lets do XServiceVersion. So services Foo and Bar in a client would have members FooServiceVersion and BarServiceVersion
…erviceVersion Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/1abc462d-6e01-4045-857d-007426a4d797
Changed the enum naming from |
PR #10061 unconditionally used the full namespace for API version enum names in multi-service scenarios. This produces unnecessarily verbose names when services have distinct last namespace segments. This PR changes the logic to only use the full namespace when there's an actual collision, and restores the
ClientHelper.BuildNameForServicehelper for proper prefix/suffix-aware naming. The collision-aware naming applies to all multi-service generated members — enum type names, version property names, and latest version field names all useBuildNameForServiceby default, falling back to full namespace only when last segments collide. The enum type naming follows the{X}ServiceVersionpattern (e.g.,KeyVaultServiceVersion) rather thanService{X}Version.Behavior
Sample.KeyVault,Sample.StorageSampleKeyVaultVersionKeyVaultServiceVersionSample.KeyVault,Sample.StorageSampleKeyVaultApiVersionKeyVaultApiVersionSample.KeyVault,Sample.StorageLatestServiceKeyVaultVersionLatestKeyVaultVersionAzure.One.Tests,Azure.Two.TestsAzureOneTestsVersionAzureOneTestsVersion(collision onTests)Azure.One.Tests,Azure.Two.TestsAzureOneTestsApiVersionAzureOneTestsApiVersion(collision onTests)Changes
ClientHelper.cs— restoredBuildNameForServicehelper (removed in PR Fix duplicate API version field names for multi-service clients with colliding namespaces #10061) that extracts the last namespace segment and ensures proper prefix/suffix without duplication; added sharedGetLastNamespaceSegmentandHasLastSegmentCollisionstatic helpersClientHelperTests.cs— restored all 22 tests forBuildNameForServiceApiVersionEnumProvider.BuildName()— usesClientHelper.BuildNameForServicewith empty prefix and"ServiceVersion"suffix for the non-collision case, producing{X}ServiceVersionnames; falls back to full namespace only when last segments collide; delegates to sharedClientHelpermethods instead of local helpersClientOptionsProvider.BuildVersionProperties()— usesClientHelper.BuildNameForServicefor version property names in the non-collision case; falls back to full namespace only when last segments collideClientOptionsProvider.BuildLatestVersionsFields()— usesClientHelper.BuildNameForServicefor latest version field names in the non-collision case; falls back to full namespace only when last segments collideMultiServiceClient_WithCollidingLastSegments_UsesFullNamespacetest andMultiServiceClient_SameLastSegment_ProducesUniqueVersionEnumstest with TestData golden file validationOriginal prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.