Fix: Use client.apiVersions as source of truth for API version enum generation#9715
Conversation
This fixes the issue where API versions were being lost when adding new versions. The parseApiVersions() function was incorrectly reading from sdkPackage.enums instead of using client.apiVersions, which is the source of truth from TCGC. - Removed logic that reads from apiVersionEnum.values - Simplified parseApiVersions to always use client.apiVersions - Removed unused imports (UsageFlags, containsMultiServiceClient) Fixes microsoft/typespec#<issue-number> Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
packages/http-client-csharp/emitter/test/Unit/client-model-builder.test.ts
Show resolved
Hide resolved
…ing test patterns Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
packages/http-client-csharp/emitter/test/Unit/client-model-builder.test.ts
Outdated
Show resolved
Hide resolved
…test patterns Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
…ir own version enum Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
packages/http-client-csharp/emitter/src/lib/client-model-builder.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
|
@copilot the new tests are failing. Please run and ensure that they are passing. AssertionError: Unexpected diagnostics: |
…to work correctly Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Fixed! The tests were failing because |
|
@copilot lint is failing |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Fixed! Removed the duplicate |
Fix ApiVersionEnum Missing Existing Members ✅
Problem
When adding new API versions to a TypeSpec service, the C# emitter was losing existing versions. The
parseApiVersions()function was reading fromsdkPackage.enumsinstead ofclient.apiVersions, which TCGC correctly populates with all versions from the@versionedenum.Root Cause
The
parseApiVersions()function had logic that:client.apiVersions✅apiVersionEnum.values❌client.apiVersionsUser confirmed that:
client.apiVersionsBut the emitter was ignoring
client.apiVersionsand reading fromsdkPackage.enumsinstead, which may not have all values populated correctly at that point.Solution
Simplified
parseApiVersions()to always useclient.apiVersionsas the source of truth:Changes Made
parseApiVersions()in http-client-csharp emitterUsageFlags,containsMultiServiceClient)Tests Added
Two new test cases in the existing
parseApiVersionsdescribe block inclient-model-builder.test.ts:Both tests follow the pattern from line 208 test: using
IsNamespaceNeeded: falseand defining a complete namespace with@serviceand@versioneddecorators.Impact Analysis
client.apiVersionsdirectly)client.apiVersionsdirectly)Test & Lint Results
Files Changed
packages/http-client-csharp/emitter/src/lib/client-model-builder.ts(13 deletions, 5 additions)packages/http-client-csharp/emitter/test/Unit/client-model-builder.test.ts(64 additions, 12 deletions)Ready for merge! 🚀
Original prompt
💡 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.