Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing interface declaration for inherited error models #5891

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed a bug in generation when a referenced schema in an allOf was a primitive [#5701](https://github.com/microsoft/kiota/issues/5701).
- Fixed a bug where inherited error models would be missing interface declarations. [#5888](https://github.com/microsoft/kiota/issues/5888)

## [1.21.0] - 2024-12-05

Expand Down Expand Up @@ -1519,4 +1520,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Initial GitHub release

2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ parent is CodeType parentType &&
foreach (var implement in currentParent
.StartBlock
.Implements
.Where(pi => !currentClass.Usings.Any(ci => ci.Name.Equals(pi.Name, StringComparison.OrdinalIgnoreCase))))
.Where(pi => !currentClass.Usings.Any(ci => !ci.IsExternal && ci.Name.Equals(pi.Name, StringComparison.OrdinalIgnoreCase))))
{
currentClass.StartBlock.AddImplements((CodeType)implement.Clone());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
{
Name = "otherNs",
});
otherModel.StartBlock.AddImplements(new CodeType
{
Name = "IAdditionalDataHolder",
IsExternal = true
});
var declaration = model.StartBlock;
declaration.Inherits = new CodeType
{
Expand All @@ -125,6 +130,7 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
Assert.Contains(model.Properties, x => x.Name.Equals("OtherProp"));
Assert.Contains(model.Methods, x => x.Name.Equals("otherMethod"));
Assert.Contains(model.Usings, x => x.Name.Equals("otherNs"));
Assert.Contains(model.StartBlock.Implements, x => x.Name.Equals("IAdditionalDataHolder"));
}
[Fact]
public async Task AddsUsingsForErrorTypesForRequestExecutorAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
{
Name = "otherNs",
});
otherModel.StartBlock.AddImplements(new CodeType
{
Name = "IAdditionalDataHolder",
IsExternal = true
});
var declaration = model.StartBlock;
declaration.Inherits = new CodeType
{
Expand All @@ -588,6 +593,10 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
Assert.Contains(model.Properties, x => x.Name.Equals("otherProp"));
Assert.Contains(model.Methods, x => x.Name.Equals("otherMethod"));
Assert.Contains(model.Usings, x => x.Name.Equals("otherNs"));

var modelInterface = root.FindChildByName<CodeInterface>("somemodelable");
Assert.NotNull(modelInterface);
Assert.Contains(modelInterface.StartBlock.Implements, x => x.Name.Equals("AdditionalDataHolder", StringComparison.OrdinalIgnoreCase));
}
[Fact]
public async Task AddsUsingsForErrorTypesForRequestExecutorAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
{
Name = "otherNs",
});
otherModel.StartBlock.AddImplements(new CodeType
{
Name = "IAdditionalDataHolder",
IsExternal = true
});
var declaration = model.StartBlock;
declaration.Inherits = new CodeType
{
Expand All @@ -95,6 +100,7 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
Assert.Contains(model.Methods, x => x.Name.Equals("otherMethod"));
Assert.Contains(model.Usings, x => x.Name.Equals("otherNs"));
Assert.Equal("ApiException", model.StartBlock.Inherits.Name);
Assert.Contains(model.StartBlock.Implements, x => x.Name.Equals("AdditionalDataHolder", StringComparison.OrdinalIgnoreCase));
}
[Fact]
public async Task AddsUsingsForErrorTypesForRequestExecutorAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
{
Name = "otherNs",
});
otherModel.StartBlock.AddImplements(new CodeType
{
Name = "IAdditionalDataHolder",
IsExternal = true
});
var declaration = model.StartBlock;
declaration.Inherits = new CodeType
{
Expand All @@ -170,6 +175,7 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
Assert.Contains(model.Properties, x => x.Name.Equals("other_prop"));
Assert.Contains(model.Methods, x => x.Name.Equals("other_method"));
Assert.Contains(model.Usings, x => x.Name.Equals("otherNs"));
Assert.Contains(model.StartBlock.Implements, x => x.Name.Equals("AdditionalDataHolder", StringComparison.OrdinalIgnoreCase));
}
[Fact]
public async Task AddsUsingsForErrorTypesForRequestExecutorAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,32 @@ public async Task InlineParentOnErrorClassesWhichAlreadyInheritAsync()
new CodeUsing
{
Name = "otherNs",
},
new CodeUsing
{
Name = "AdditionalDataHolder",
});
otherModel.StartBlock.AddImplements(new CodeType
{
Name = "AdditionalDataHolder",
IsExternal = true
});
model.StartBlock.Inherits = new CodeType
{
TypeDefinition = otherModel
};
await ILanguageRefiner.RefineAsync(new GenerationConfiguration { Language = GenerationLanguage.TypeScript }, root);

Assert.DoesNotContain("otherProp", model.Properties.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase); // we're not inlining since base error for TS is an interface
Assert.DoesNotContain("otherMethod", model.Methods.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase);
Assert.DoesNotContain("otherNs", model.Usings.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase);
var interfaceModel = root.FindChildByName<CodeInterface>("somemodel");
Assert.NotNull(interfaceModel);

Assert.DoesNotContain("otherProp", interfaceModel.Properties.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase); // we're not inlining since base error for TS is an interface
Assert.DoesNotContain("otherMethod", interfaceModel.Methods.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase);
Assert.DoesNotContain("otherNs", interfaceModel.Usings.Select(static x => x.Name), StringComparer.OrdinalIgnoreCase);

var interfaceOtherModel = root.FindChildByName<CodeInterface>("otherModel");
Assert.NotNull(interfaceOtherModel);
Assert.Contains(interfaceOtherModel.StartBlock.Implements, x => x.Name.Equals("AdditionalDataHolder", StringComparison.OrdinalIgnoreCase));
}
[Fact]
public async Task AddsUsingsForErrorTypesForRequestExecutorAsync()
Expand Down
Loading