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>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4fcb1063-c7b2-4ae0-bdda-fd4ba28c24ec Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Done in 5080471. Merged |
commit: |
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot lets update one of the model properties in https://github.com/microsoft/typespec/tree/main/packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec to use exactName
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/415f88ad-5491-45f7-b9b0-45eff15ff8e6 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…egenerate Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/415f88ad-5491-45f7-b9b0-45eff15ff8e6 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Done in 997509a. Added |
|
@copilot spell check is failing |
…sesExactName test Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/6657becf-b44b-42e2-b623-0ed820861ef2 Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Fixed in 81e306e. The Consistency / Spell check job flagged |
TCGC 0.68.0 added
exact(), which marks a@clientNamevalue to be preserved verbatim by emitters. This change plumbs the newisExactNameflag through the C# emitter and generator so that marked names bypass.ToIdentifierName()casing.Changes
isExactName?: booleantoInputModelType,InputEnumType,InputLiteralType,InputUnionType, andInputPropertyTypeBase. Populated from the corresponding SDK types intype-converter.ts,operation-converter.ts, andclient-converter.ts.IsExactNameto theInputTypeandInputPropertybase classes and extended the JSON converters (model, enum, literal, union, model property, and method/header/query/path/body/endpoint parameter) to deserialize the field.ModelProvider.BuildName,EnumProvider.BuildName, andPropertyProviderskip.ToIdentifierName()whenIsExactNameis true._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,SdkConstantType,SdkUnionType,SdkNullableType,SdkClientInitializationType) and onSdkModelPropertyTypeBase.SdkServiceMethodBaseandSdkClientTypedo not carry the flag, so operations and clients themselves are not 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 (and, after mergingmain, the newserializationOptionsfield).PropertyProviderTestscases for exact-name model and property.model-type.test.tscases verifying propagation fromexact()on every target TCGC supports (model, model property, enum, union, method parameter, query parameter, header parameter, path parameter, body parameter), plus a negative case.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 and that the rest clientCreate*Requestmethod references the exact wire name when building the request URI.InputFactory.MethodParameterandInputFactory.QueryParametertest helpers with anisExactNameparameter.