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 }