Skip to content

Commit

Permalink
Merge pull request #4762 from microsoft/andrueastman/fixWarnings
Browse files Browse the repository at this point in the history
Fixes a bug where warnings about discriminator not being inherited were generated
  • Loading branch information
andrueastman authored Jun 3, 2024
2 parents b3ec1e3 + 4b7e167 commit 399a577
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,13 @@ public async Task AddsDiscriminatorMappingsAllOfImplicit()
var entityClass = codeModel.FindChildByName<CodeClass>("entity");
var directoryObjectClass = codeModel.FindChildByName<CodeClass>("directoryObject");
var userClass = codeModel.FindChildByName<CodeClass>("user");
mockLogger.Verify(logger => logger.Log(
It.Is<LogLevel>(logLevel => logLevel == LogLevel.Warning),
It.Is<EventId>(eventId => eventId.Id == 0),
It.Is<It.IsAnyType>((@object, @type) => @object.ToString().Contains(" is not inherited from ", StringComparison.OrdinalIgnoreCase) && @type.Name == "FormattedLogValues"),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Never);
Assert.NotNull(entityClass);
Assert.NotNull(directoryObjectClass);
Assert.NotNull(userClass);
Expand Down

0 comments on commit 399a577

Please sign in to comment.