From 05ca93084ae838be3ade43eaf2899c8abde44f3a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:48:11 +0000 Subject: [PATCH 1/2] Initial plan From 91d455fa4a6ddd0ce440e51267bc00fbc598552f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:59:21 +0000 Subject: [PATCH 2/2] fix: exclude BackingStore getter/setter methods from Go model interfaces Resolve issue where GetBackingStore method was unnecessarily emitted in Go model interfaces when backing store is enabled, even though it's already defined in the BackedModel interface they compose from. This was causing redundant code generation. The fix modifies CommonLanguageRefiner.cs to filter out methods that access BackingStore properties (similar to existing AdditionalData filtering) when copying model classes to interfaces. Co-authored-by: baywet <7905502+baywet@users.noreply.github.com> --- CHANGELOG.md | 1 + .../Refiners/CommonLanguageRefiner.cs | 2 +- .../Refiners/GoLanguageRefinerTests.cs | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3d0ebe85..5b971fe70f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fixed a bug where TypeScript deserialization of oneOf types with inheritance would incorrectly place derived type properties in additionalProperties. [#6896](https://github.com/microsoft/kiota/issues/6896) +- Fixed a bug where Go model interfaces would redundantly include GetBackingStore method when backing store was enabled, even though it's already defined in the composed BackedModel interface. ## [1.29.0] - 2025-10-23 diff --git a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs index d5ae1ff21c..af52fb82b3 100644 --- a/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs +++ b/src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs @@ -1273,7 +1273,7 @@ private static CodeInterface CopyClassAsInterface(CodeClass modelClass, Func x.IsOfKind(CodeMethodKind.Getter, CodeMethodKind.Setter, CodeMethodKind.Factory) && - !(x.AccessedProperty?.IsOfKind(CodePropertyKind.AdditionalData) ?? false))) + !(x.AccessedProperty?.IsOfKind(CodePropertyKind.AdditionalData, CodePropertyKind.BackingStore) ?? false))) { if (method.ReturnType is CodeType methodReturnType && !methodReturnType.IsExternal) diff --git a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs index 652e1580b8..0ee2398ef9 100644 --- a/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs +++ b/tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs @@ -1388,5 +1388,49 @@ public async Task EscapesReservedKeywordsInMethodParametersAsync() Assert.DoesNotContain(method.Parameters, p => p.Name == "type"); Assert.DoesNotContain(method.Parameters, p => p.Name == "select"); } + [Fact] + public async Task DoesNotIncludeBackingStoreMethodsInInterfacesAsync() + { + var model = root.AddClass(new CodeClass + { + Name = "somemodel", + Kind = CodeClassKind.Model, + }).First(); + + // The GoRefiner will automatically add getter/setter methods for properties + var backingStoreProperty = model.AddProperty(new CodeProperty + { + Name = "backingStore", + Kind = CodePropertyKind.BackingStore, + Type = new CodeType + { + Name = "BackingStore", + IsExternal = true, + }, + }).First(); + + var customProperty = model.AddProperty(new CodeProperty + { + Name = "customProp", + Kind = CodePropertyKind.Custom, + Type = new CodeType + { + Name = "string", + IsExternal = true, + }, + }).First(); + + await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.Go, UsesBackingStore = true }, root); + + var codeFile = root.GetChildElements(true).OfType().First(); + var inter = codeFile.GetChildElements(true).OfType().First(); + + // The interface should have getter and setter for the custom property, but not for the backing store + Assert.DoesNotContain(inter.Methods, m => m.Name == "GetBackingStore"); + Assert.DoesNotContain(inter.Methods, m => m.Name == "SetBackingStore"); + Assert.Contains(inter.Methods, m => m.Name == "GetCustomProp"); + Assert.Contains(inter.Methods, m => m.Name == "SetCustomProp"); + Assert.Equal(2, inter.Methods.Count()); + } #endregion }