Support TCGC exact() client name in C# emitter#10728
Conversation
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/b465cdf8-5db5-43ea-97f0-f615be72ddc1 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
exact() client name in C# emitter
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot we need to ensure we cover all targets specified in https://azure.github.io/typespec-azure/docs/libraries/typespec-client-generator-core/reference/decorators/#@Azure.ClientGenerator.Core.clientName and add tests in both the generator and in the emitter. Also, we need to add test cases for when there is also a custom type that attempts to rename the member. In this scenario, the custom code should still win even when exactName is specified
|
@copilot we need to also regenerate all the test libraries and ensure all existing tests are passing. |
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/d49e2964-d8d7-4d25-a10c-3ed3b2380518 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Added in 43ccb46:
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:
|
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/e393b22c-6092-402e-b27d-2042b1f51026 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Regenerated all test libraries (74 |
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot lets also add test coverage for all members and their related serialization. For model's and their properties, we should validate that the serialization is constructed with the exact name. Same for operations and their parameters. We need to be thorough here.
… test value to access_token Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/9283803c-c529-4be6-aede-8fe1a7e8b509 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Added serialization and method-parameter coverage in 870e9b8:
|
|
@copilot lets pull the latest from main and resolve the merge conflicts. Once they are resolved, we should regenerate all the test projects. |
…-client-name # Conflicts: # packages/http-client-csharp/emitter/src/lib/operation-converter.ts # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputBodyParameterConverter.cs # packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/documentation/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/encode/array/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/encode/bytes/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/encode/datetime/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/encode/duration/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/encode/numeric/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/basic/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/body-optionality/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/parameters/spread/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/payload/json-merge-patch/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/payload/media-type/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/payload/multipart/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/payload/pageable/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/payload/xml/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/serialization/encoded-name/json/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/special-words/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/array/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/dictionary/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/extensible/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/enum/fixed/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/empty/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/enum-discriminator/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/nested-discriminator/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/not-discriminated/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/recursive/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/inheritance/single-discriminator/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/usage/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/model/visibility/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/additional-properties/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/nullable/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/optionality/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/property/value-types/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/scalar/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/type/union/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/added/v2/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/madeOptional/v2/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/removed/v2Preview/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/renamedFrom/v2/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/returnTypeChangedFrom/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/returnTypeChangedFrom/v2/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v1/tspCodeModel.json # packages/http-client-csharp/generator/TestProjects/Spector/http/versioning/typeChangedFrom/v2/tspCodeModel.json Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot there are ci checks failing. We need to regenerate all the test libraries and ensure all existing tests, including spector tests, are passing
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
|
@copilot resolve merge conflicts |
…-client-name # Conflicts: # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputEnumTypeValueConverter.cs # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/common/InputFactory.cs Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Merged
Full generator suite passes (1512) and ClientModel suite passes (1343). |
TCGC 0.68.0 added
exact(), which marks a@clientNamevalue to be preserved verbatim by emitters. TCGC 0.68.2 extended the flag to enum values and toSdkClientType/SdkServiceMethodBase. This change plumbs the newisExactNameflag through the C# emitter and generator so that marked names bypass.ToIdentifierName()casing.Changes
isExactName?: booleantoInputModelType,InputEnumType,InputEnumValueType,InputLiteralType,InputUnionType,InputPropertyTypeBase,InputClient,InputServiceMethodBase, andInputOperation. Populated from the corresponding SDK types intype-converter.ts,operation-converter.ts, andclient-converter.ts(includingcreateEnumValueTypeforSdkEnumValueType/SdkConstantType). Inclient-converter.ts, the multi-service…Clientsuffix is also skipped whenisExactNameis true so the verbatim name is preserved.IsExactNameto theInputTypeandInputPropertybase classes, toInputClient,InputServiceMethod, andInputOperation, and extended the JSON converters (model, enum, enum value, literal, union, model property, method/header/query/path/body/endpoint parameter, client, basic/paging/LRO/LRO-paging service method, and operation) to deserialize the field.ModelProvider.BuildName,EnumProvider.BuildName,PropertyProvider,FixedEnumProvider.BuildFields,ExtensibleEnumProvider.BuildEnumValues, andClientProvider.BuildNameskip.ToIdentifierName()whenIsExactNameis true.ClientProvider.GetCleanOperationNamereturns the operation name verbatim — skipping both casing and theList→Getconvention rename — when the service methodIsExactNameis true. For extensible enums, the exact-name value is preserved verbatim on both the private…Valuefield and the public property.ParameterProvider.GetVariableExpressionskips.ToVariableName()camelCasing when the underlyingInputParameter.IsExactNameis true so the generated C# parameter (in convenience methods, protocol methods, and rest clientCreate*Requestsignatures) uses the exact spec name (e.g.string api_keyinstead ofstring apiKey)._specPropertiesMapnow keys spec properties by their exact name whenIsExactNameis true, so[CodeGenMember("snake_case_name")]lookup still matches when the spec property name is preserved exactly. This ensures custom code rename wins overIsExactName.isExactNameon type interfaces (SdkModelType,SdkEnumType,SdkEnumValueType,SdkConstantType,SdkUnionType,SdkNullableType,SdkClientInitializationType), onSdkModelPropertyTypeBase, onSdkClientType, and onSdkServiceMethodBase. All of these targets are now in scope; method parameters are covered becauseSdkMethodParameterextendsSdkModelPropertyTypeBase.@clientName(Azure.ClientGenerator.Core.exact("exact_name_property"), "csharp")toRoundTripModel.exactNamePropertyinSample-TypeSpec.tspso the generatedRoundTripModel.csexposespublic string exact_name_property { get; set; }verbatim and the serializer writes the wire name viaWritePropertyName("exact_name_property"u8).tspCodeModel.jsontest fixtures (Sample-TypeSpec + Spector projects) were regenerated to include the newisExactNamefield on types, properties, enum values, clients, methods, and operations (and, after mergingmain, the newserializationOptionsfield).PropertyProviderTestscases for exact-name model and property.EnumProviderTestscases for IsExactName-marked values on fixed string-based, fixed int-based, and extensible string-based enums.model-type.test.tscases verifying propagation fromexact()on every target TCGC supports (model, model property, enum, enum value, union, method parameter, query parameter, header parameter, path parameter, body parameter, client, and operation), plus a negative case.ClientProviderTestscases — client name preserved verbatim, regression check that a non-exact client name still goes through PascalCase, exact-name operation preserved verbatim, exact-nameListoperation is NOT renamed toGetAll, and regression check that a non-exactListstill becomesGetAll.CustomCodeWinsOverIsExactNameverifying that a[CodeGenMember]custom property still wins over anIsExactName-marked spec property (generated property is filtered out, custom name is used, spec serialized name is preserved on the custom property). Uses the realistic .NET-idiomaticaccess_token/AccessTokenOAuth scenario.IsExactNamePropertySerializationUsesExactNameandIsExactNameModelSerializationUsesExactNamevalidate the generatedJsonModelWriteCoreandDeserialize<ModelName>bodies via full-bodyHelpers.GetExpectedFromFile()comparisons against checked-in TestData files (IsExactNamePropertySerializationUsesExactName(serialize).cs,IsExactNamePropertySerializationUsesExactName(deserialize).cs,IsExactNameModelSerializationUsesExactName.cs).ExactNameMethodParameterPreservedInRestClientasserts both convenience and protocol method parameters preserve the exact name verbatim (including the C# parameter identifier, not just the wire name) and that the rest clientCreate*Requestmethod references the exact wire name when building the request URI.InputFactory.MethodParameter,InputFactory.QueryParameter,InputFactory.EnumMember.{String,Int32,Float32,Float64},InputFactory.Operation,InputFactory.BasicServiceMethod, andInputFactory.Clienttest helpers with anisExactNameparameter; promotedInputFactory.Enumfromprivatetopublicfor direct construction of enums with hand-built value lists.