From dbdc2f3f28c69807638bc5a99524689a916d195d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 31 May 2024 15:16:33 +0100 Subject: [PATCH] fix: Disambiguate resource name collisions For example, if an `Account` resource has `name` and `account_name` properties, we don't want to generate an `AccountName` property in GAPIC, as that collides with the one generated by protoc. Instead, we generate `NameAsAccountName`. No tests for this edge case, but I've run the generator against the Merchant Accounts API (which flagged this up) and the result builds where it didn't before. Fixes b/343924087 --- Google.Api.Generator/ProtoUtils/ResourceDetails.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Google.Api.Generator/ProtoUtils/ResourceDetails.cs b/Google.Api.Generator/ProtoUtils/ResourceDetails.cs index da97637e..9d75163b 100644 --- a/Google.Api.Generator/ProtoUtils/ResourceDetails.cs +++ b/Google.Api.Generator/ProtoUtils/ResourceDetails.cs @@ -139,10 +139,11 @@ public Field(FieldDescriptor fieldDesc, Definition resourceDef, IReadOnlyList f.CSharpPropertyName() == unqualifiedName); + ResourcePropertyName = (requireIdentifier ? $"{UnderlyingPropertyName}As" : "") + unqualifiedName; InnerDefs = innerDefs; ContainsWildcard = containsWildcard; }