Skip to content

Commit

Permalink
Fixes missing imports in java generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Jun 4, 2024
1 parent a031b6d commit 517d5f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761)
- Fix scalar member composed type serialization in PHP [#2827](https://github.com/microsoft/kiota/issues/2827)
- Trims unused components from output openApi document when generating plugins [#4672](https://github.com/microsoft/kiota/issues/4672)
- Fixes missing imports for UntypedNode when backingstore is enabled in Java.

## [1.14.0] - 2024-05-02

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/JavaRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static void AddEnumSetImport(CodeElement currentElement)
AbstractionsNamespaceName, "QueryParameters"),
new (static x => x is CodeClass @class && @class.OriginalComposedType is CodeIntersectionType intersectionType && intersectionType.Types.Any(static y => !y.IsExternal),
SerializationNamespaceName, "ParseNodeHelper"),
new (static x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.Custom) && prop.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase),
new (static x => (x is CodeMethod @method && @method.IsOfKind(CodeMethodKind.Getter, CodeMethodKind.Setter) && @method.AccessedProperty != null && (@method.AccessedProperty.IsOfKind(CodePropertyKind.Custom) && @method.AccessedProperty.Type.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase) )) ,
SerializationNamespaceName, KiotaBuilder.UntypedNodeName),
new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor, CodeMethodKind.RequestGenerator) && method.Parameters.Any(static y => y.IsOfKind(CodeParameterKind.RequestBody) && y.Type.Name.Equals(MultipartBodyClassName, StringComparison.OrdinalIgnoreCase)),
AbstractionsNamespaceName, MultipartBodyClassName)
Expand Down
10 changes: 6 additions & 4 deletions tests/Kiota.Builder.Tests/Refiners/JavaLanguageRefinerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,10 @@ public async Task SplitsLongRefiners()
Assert.Equal("String", model.Methods.First(static x => x.IsOverload).Parameters.First().Type.Name);
}

[Fact]
public async Task AddsUsingForUntypedNode()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task AddsUsingForUntypedNode(bool usesBackingStore)
{
var model = root.AddClass(new CodeClass
{
Expand All @@ -720,11 +722,11 @@ public async Task AddsUsingForUntypedNode()
IsExternal = true
},
}).First();
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java }, root);
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Java, UsesBackingStore = usesBackingStore }, root);
Assert.Equal(KiotaBuilder.UntypedNodeName, property.Type.Name);
Assert.NotEmpty(model.StartBlock.Usings);
var nodeUsing = model.StartBlock.Usings.Where(static declaredUsing => declaredUsing.Name.Equals(KiotaBuilder.UntypedNodeName, StringComparison.OrdinalIgnoreCase)).ToArray();
Assert.Single(nodeUsing);
Assert.Equal(2, nodeUsing.Length); // one for the getter and another for setter. Writer will unionise
Assert.Equal("com.microsoft.kiota.serialization", nodeUsing[0].Declaration.Name);
}
#endregion
Expand Down

0 comments on commit 517d5f5

Please sign in to comment.