diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e10fa314..a469a745b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixes a bug where indexers in include/exclude patters were not normalized if the indexer was the last segment without a slash at the end [#4715](https://github.com/microsoft/kiota/issues/4715) - Fixes a bug where CLI generation doesnot handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707) - Fixed a bug where models would not be created when a multipart content schema existed with no encoding [#4734](https://github.com/microsoft/kiota/issues/4734) +- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761) ## [1.14.0] - 2024-05-02 diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 81613e912f..226e831e78 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -2164,7 +2164,8 @@ internal static void AddDiscriminatorMethod(CodeClass newClass, string discrimin } if (baseClass is not null && (result.TypeDefinition is not CodeClass codeClass || codeClass.StartBlock.Inherits is null)) { - logger.LogWarning("Discriminator {ComponentKey} is not inherited from {ClassName}.", componentKey, baseClass.Name); + if (!baseClass.Equals(result.TypeDefinition))// don't log warning if the discriminator points to the base type itself as this is implicitly the default case. + logger.LogWarning("Discriminator {ComponentKey} is not inherited from {ClassName}.", componentKey, baseClass.Name); return null; } return result; diff --git a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs index e70aff7d30..fc0df2d7d5 100644 --- a/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs +++ b/tests/Kiota.Builder.Tests/KiotaBuilderTests.cs @@ -3426,6 +3426,13 @@ public async Task AddsDiscriminatorMappingsAllOfImplicit() var entityClass = codeModel.FindChildByName("entity"); var directoryObjectClass = codeModel.FindChildByName("directoryObject"); var userClass = codeModel.FindChildByName("user"); + mockLogger.Verify(logger => logger.Log( + It.Is(logLevel => logLevel == LogLevel.Warning), + It.Is(eventId => eventId.Id == 0), + It.Is((@object, @type) => @object.ToString().Contains(" is not inherited from ", StringComparison.OrdinalIgnoreCase) && @type.Name == "FormattedLogValues"), + It.IsAny(), + It.IsAny>()), + Times.Never); Assert.NotNull(entityClass); Assert.NotNull(directoryObjectClass); Assert.NotNull(userClass);