Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed float to string conversion with invariant culture.
- Fixed a bug where vendor mime types would be ignored. [#3666](https://github.com/microsoft/kiota/issues/3666)
- Fixed a bug where additional parameter would be stripped from accept header. [#3667](https://github.com/microsoft/kiota/issues/3667), [#3667](https://github.com/microsoft/kiota/issues/3668)
- Generation for Java no longer utilizes Async api components. [Kiota-Java #175](https://github.com/microsoft/kiota-java/issues/175)

## [1.8.1] - 2023-11-02

Expand Down
2 changes: 1 addition & 1 deletion it/java/basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>0.7.8</kiota-java.version>
<kiota-java.version>0.9.0</kiota-java.version>
</properties>

<dependencies>
Expand Down
11 changes: 5 additions & 6 deletions it/java/basic/src/test/java/BasicAPITest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import apisdk.ApiClient;
import com.microsoft.kiota.ApiException;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
import com.microsoft.kiota.http.OkHttpRequestAdapter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class BasicAPITest {
Expand All @@ -17,13 +17,12 @@ void basicTest() throws Exception {
var client = new ApiClient(adapter);

var exception = Assertions.assertThrows(
ExecutionException.class,
() -> client.api().v1().topics().get().get(1, TimeUnit.SECONDS)
ApiException.class,
() -> client.api().v1().topics().get()
);

Assertions.assertNotNull(exception.getCause());
Assertions.assertTrue(exception.getCause() instanceof apisdk.models.Error);
var error = (apisdk.models.Error) exception.getCause();
Assertions.assertTrue(exception instanceof apisdk.models.Error);
var error = (apisdk.models.Error) exception;

Assertions.assertEquals("my-sample-id", error.getId());
Assertions.assertEquals(123, error.getCode());
Expand Down
2 changes: 1 addition & 1 deletion it/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<kiota-java.version>0.7.8</kiota-java.version>
<kiota-java.version>0.9.0</kiota-java.version>
</properties>

<dependencies>
Expand Down
34 changes: 15 additions & 19 deletions src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,27 +503,30 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
}
}
var factoryParameter = codeElement.ReturnType is CodeType returnCodeType && returnCodeType.TypeDefinition is CodeClass ? $"{returnType}::{FactoryMethodName}" : $"{returnType}.class";
writer.WriteLine($"return this.requestAdapter.{sendMethodName}({RequestInfoVarName}, {factoryParameter}, {errorMappingVarName});");
var returnPrefix = codeElement.ReturnType.Name.Equals("void", StringComparison.OrdinalIgnoreCase) ? string.Empty : "return ";
writer.WriteLine($"{returnPrefix}this.requestAdapter.{sendMethodName}({RequestInfoVarName}, {factoryParameter}, {errorMappingVarName});");
}
private string GetSendRequestMethodName(bool isCollection, string returnType, bool isEnum)
{
if (conventions.PrimitiveTypes.Contains(returnType))
if (isCollection)
return "sendPrimitiveCollectionAsync";
return "sendPrimitiveCollection";
else
return "sendPrimitiveAsync";
return "sendPrimitive";
else if (isEnum)
if (isCollection)
return "sendEnumCollectionAsync";
return "sendEnumCollection";
else
return "sendEnumAsync";
else if (isCollection) return "sendCollectionAsync";
return "sendAsync";
return "sendEnum";
else if (isCollection) return "sendCollection";
return "send";
}
private const string RequestInfoVarName = "requestInfo";
private const string RequestConfigVarName = "requestConfig";
private static void WriteGeneratorOrExecutorMethodCall(CodeMethod codeElement, RequestParams requestParams, CodeClass parentClass, LanguageWriter writer, string prefix, CodeMethodKind codeMethodKind)
{
if (codeElement.Kind is CodeMethodKind.RequestExecutor && codeElement.ReturnType.Name.Equals("void", StringComparison.OrdinalIgnoreCase) && prefix.Trim().Equals("return", StringComparison.OrdinalIgnoreCase))
prefix = string.Empty;
var methodName = parentClass
.Methods
.FirstOrDefault(x => x.IsOfKind(codeMethodKind) && x.HttpMethod == codeElement.HttpMethod)
Expand Down Expand Up @@ -688,17 +691,14 @@ private void WriteSerializationMethodCall(CodeProperty otherProp, CodeMethod met
private static readonly BaseCodeParameterOrderComparer parameterOrderComparer = new();
private string GetFinalReturnType(CodeMethod code, string returnType)
{
var voidType = code.IsAsync ? "Void" : "void";
if (code.ReturnType is CodeType { TypeDefinition: CodeEnum { Flags: true }, IsCollection: false })
returnType = $"EnumSet<{returnType}>";
var returnTypeAsyncPrefix = code.IsAsync ? "java.util.concurrent.CompletableFuture<" : string.Empty;
var returnTypeAsyncSuffix = code.IsAsync ? ">" : string.Empty;
var reType = returnType.Equals("void", StringComparison.OrdinalIgnoreCase) ? voidType : returnType;
var reType = returnType.Equals("void", StringComparison.OrdinalIgnoreCase) ? "void" : returnType;
var collectionCorrectedReturnType = code.ReturnType.IsArray && code.IsOfKind(CodeMethodKind.RequestExecutor) ?
$"Iterable<{returnType.StripArraySuffix()}>" :
reType;
var isConstructor = code.IsOfKind(CodeMethodKind.Constructor, CodeMethodKind.ClientConstructor, CodeMethodKind.RawUrlConstructor);
var finalReturnType = isConstructor ? string.Empty : $"{returnTypeAsyncPrefix}{collectionCorrectedReturnType}{returnTypeAsyncSuffix}";
var finalReturnType = isConstructor ? string.Empty : $"{collectionCorrectedReturnType}";
return finalReturnType.Trim();
}
private void WriteMethodPrototype(CodeMethod code, LanguageWriter writer, string returnType)
Expand Down Expand Up @@ -729,20 +729,16 @@ private void WriteMethodDocumentation(CodeMethod code, LanguageWriter writer, st
{
var returnVoid = baseReturnType.Equals("void", StringComparison.OrdinalIgnoreCase);
// Void returns, this includes constructors, should not have a return statement in the JavaDocs.
var returnRemark = returnVoid ? string.Empty : (code.IsAsync switch
{
true => $"@return a CompletableFuture of {baseReturnType}",
false => $"@return a {finalReturnType}",
});
var returnRemark = returnVoid ? string.Empty : $"@return a {finalReturnType}";
conventions.WriteLongDescription(code,
writer,
code.Parameters
.Where(static x => x.Documentation.DescriptionAvailable)
.OrderBy(static x => x.Name, StringComparer.OrdinalIgnoreCase)
.Select(x => $"@param {x.Name} {JavaConventionService.RemoveInvalidDescriptionCharacters(x.Documentation.Description)}")
.Union(new[] { returnRemark }));
if (!returnVoid || code.IsAsync) //Nullable/Nonnull annotations for returns are a part of Method Documentation
writer.WriteLine(code.ReturnType.IsNullable && !code.IsAsync ? "@jakarta.annotation.Nullable" : "@jakarta.annotation.Nonnull");
if (!returnVoid) //Nullable/Nonnull annotations for returns are a part of Method Documentation
writer.WriteLine(code.ReturnType.IsNullable ? "@jakarta.annotation.Nullable" : "@jakarta.annotation.Nonnull");
}
private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod method)
{
Expand Down
49 changes: 5 additions & 44 deletions tests/Kiota.Builder.Tests/Writers/Java/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,8 @@ public void WritesNullableVoidTypeForExecutor()
};
writer.Write(method);
var result = tw.ToString();
Assert.Contains("CompletableFuture<Void>", result);
Assert.Contains("void", result);
Assert.DoesNotContain("@jakarta.annotation", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
Expand Down Expand Up @@ -652,7 +653,7 @@ public void WritesRequestExecutorBody()
Assert.Contains("put(\"4XX\", Error4XX::createFromDiscriminatorValue);", result);
Assert.Contains("put(\"5XX\", Error5XX::createFromDiscriminatorValue);", result);
Assert.Contains("put(\"401\", Error401::createFromDiscriminatorValue);", result);
Assert.Contains("sendAsync", result);
Assert.Contains("send", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
Expand Down Expand Up @@ -1174,7 +1175,7 @@ public void WritesRequestExecutorBodyForCollections()
AddRequestBodyParameters();
writer.Write(method);
var result = tw.ToString();
Assert.Contains("sendCollectionAsync", result);
Assert.Contains("sendCollection", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
Expand Down Expand Up @@ -1507,35 +1508,6 @@ public void WritesSerializerBody()
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
public void WritesMethodAsyncDescription()
{
setup();
method.Documentation.Description = MethodDescription;
var parameter = new CodeParameter
{
Documentation = new()
{
Description = ParamDescription,
},
Name = ParamName,
Type = new CodeType
{
Name = "String"
}
};
method.AddParameter(parameter);
writer.Write(method);
var result = tw.ToString();
Assert.Contains("/**", result);
Assert.Contains(MethodDescription, result);
Assert.Contains("@param ", result);
Assert.Contains(ParamName, result);
Assert.Contains(ParamDescription, result);
Assert.Contains("@return a CompletableFuture of", result);
Assert.Contains("*/", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
public void WritesMethodSyncDescription()
{
setup();
Expand Down Expand Up @@ -1604,24 +1576,13 @@ public void ThrowsIfParentIsNotClass()
method.Parent = CodeNamespace.InitRootNamespace();
Assert.Throws<InvalidOperationException>(() => writer.Write(method));
}
private const string TaskPrefix = "CompletableFuture<";
[Fact]
public void WritesReturnType()
{
setup();
writer.Write(method);
var result = tw.ToString();
Assert.Contains($"{TaskPrefix}{ReturnTypeName}> {MethodName}", result);// async default
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
public void DoesNotAddAsyncInformationOnSyncMethods()
{
setup();
method.IsAsync = false;
writer.Write(method);
var result = tw.ToString();
Assert.DoesNotContain(TaskPrefix, result);
Assert.Contains($"{ReturnTypeName} {MethodName}", result);// async default
AssertExtensions.CurlyBracesAreClosed(result);
}
[Fact]
Expand Down