Skip to content

Commit 339e1c2

Browse files
author
Andrew Omondi
committed
Fixes warnings
1 parent a3adac1 commit 339e1c2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646
- 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)
4747
- Fixes a bug where CLI generation doesnot handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707)
4848
- 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)
49+
- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761)
4950

5051
## [1.14.0] - 2024-05-02
5152

src/Kiota.Builder/KiotaBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,8 @@ internal static void AddDiscriminatorMethod(CodeClass newClass, string discrimin
21642164
}
21652165
if (baseClass is not null && (result.TypeDefinition is not CodeClass codeClass || codeClass.StartBlock.Inherits is null))
21662166
{
2167-
logger.LogWarning("Discriminator {ComponentKey} is not inherited from {ClassName}.", componentKey, baseClass.Name);
2167+
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.
2168+
logger.LogWarning("Discriminator {ComponentKey} is not inherited from {ClassName}.", componentKey, baseClass.Name);
21682169
return null;
21692170
}
21702171
return result;

tests/Kiota.Builder.Tests/KiotaBuilderTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,13 @@ public async Task AddsDiscriminatorMappingsAllOfImplicit()
34263426
var entityClass = codeModel.FindChildByName<CodeClass>("entity");
34273427
var directoryObjectClass = codeModel.FindChildByName<CodeClass>("directoryObject");
34283428
var userClass = codeModel.FindChildByName<CodeClass>("user");
3429+
mockLogger.Verify(logger => logger.Log(
3430+
It.Is<LogLevel>(logLevel => logLevel == LogLevel.Warning),
3431+
It.Is<EventId>(eventId => eventId.Id == 0),
3432+
It.Is<It.IsAnyType>((@object, @type) => @object.ToString().Contains(" is not inherited from ", StringComparison.OrdinalIgnoreCase) && @type.Name == "FormattedLogValues"),
3433+
It.IsAny<Exception>(),
3434+
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
3435+
Times.Never);
34293436
Assert.NotNull(entityClass);
34303437
Assert.NotNull(directoryObjectClass);
34313438
Assert.NotNull(userClass);

0 commit comments

Comments
 (0)