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

[BUG][JAVA][NATIVE][ASYNC] Java Client Native Async does not work with list #6157

Closed
3 tasks done
AceHack opened this issue May 4, 2020 · 4 comments
Closed
3 tasks done

Comments

@AceHack
Copy link

AceHack commented May 4, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [4.3.1-SNAPSHOT] What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • [No Data] What's the actual output vs expected output?
Description

ListSubscriptionsResponse is always null when calling listSubscriptions

This should return the real value

openapi-generator version

4.3.1-SNAPSHOT (No regression this a bug on a new feature)

OpenAPI declaration file content or url

OpenAPI Spec
DataLake-Subscription-SwaggerDocumentation.json.zip

Command line used for generation

in build.gradle.kts

openApiGenerate {
    inputSpec.set("https://xxx.yyy.zzz")
    validateSpec.set(true)
    generatorName.set("java")
    engine.set("mustache")
    skipOverwrite.set(false)
    outputDir.set(openApiGeneratedDir)
    apiPackage.set("datalake.subscription.api")
    invokerPackage.set("datalake.subscription.invoker")
    modelPackage.set("datalake.subscription.model")
    generateApiTests.set(false)
    generateApiDocumentation.set(false)
    generateModelTests.set(false)
    generateModelDocumentation.set(false)
    configOptions.set(mapOf(
            "java8" to "true",
            "dateLibrary" to "java8",
            "library" to "native",
            "asyncNative" to "true",
            "serializationLibrary" to "jackson"
    ))
Steps to reproduce

call listSubscriptions after generation

The code that's generated just looks wrong, looks like it always returns null.

  public CompletableFuture<ListSubscriptionsResponse> listSubscriptions (String maxItems, String ownerId, String nextToken) throws ApiException {

    HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();

    String localVarPath = "/";

    List<Pair> localVarQueryParams = new ArrayList<>();
    localVarQueryParams.addAll(ApiClient.parameterToPairs("max-items", maxItems));
    localVarQueryParams.addAll(ApiClient.parameterToPairs("owner-id", ownerId));
    localVarQueryParams.addAll(ApiClient.parameterToPairs("next-token", nextToken));

    if (!localVarQueryParams.isEmpty()) {
      StringJoiner queryJoiner = new StringJoiner("&");
      localVarQueryParams.forEach(p -> queryJoiner.add(p.getName() + '=' + p.getValue()));
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath + '?' + queryJoiner.toString()));
    } else {
      localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
    }

    localVarRequestBuilder.header("Accept", "application/json");

      localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
      if (memberVarReadTimeout != null) {
        localVarRequestBuilder.timeout(memberVarReadTimeout);
      }
      if (memberVarInterceptor != null) {
        memberVarInterceptor.accept(localVarRequestBuilder);
      }
      return memberVarHttpClient.sendAsync(
              localVarRequestBuilder.build(),
              HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
          if (localVarResponse.statusCode()/ 100 != 2) {
              return CompletableFuture.failedFuture(new ApiException(localVarResponse.statusCode(),
                  "listSubscriptions call received non-success response",
                  localVarResponse.headers(),
                  localVarResponse.body())
              );
          } else {
              return CompletableFuture.completedFuture(
                      null
              );
          }
      });
  }
@AceHack
Copy link
Author

AceHack commented May 4, 2020

This works fine with asyncNative: false by the way.

@AceHack
Copy link
Author

AceHack commented May 4, 2020

@AceHack
Copy link
Author

AceHack commented May 4, 2020

It seems the problem is here:

{{#returnValue}}
memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {})
{{/returnValue}}
{{^returnValue}}
null
{{/returnValue}}

Should be returnType instead of returnValue.

laballab added a commit to laballab/openapi-generator that referenced this issue May 4, 2020
@laballab
Copy link
Contributor

laballab commented May 4, 2020

Submitted a PR to fix this:
#6168

@wing328 wing328 closed this as completed in 30ee3f3 May 5, 2020
michaelpro1 pushed a commit to michaelpro1/openapi-generator that referenced this issue May 7, 2020
…rn (OpenAPITools#6168)

* Fix OpenAPITools#6157: Updated native template to fix null async return

Should fix issue: OpenAPITools#6157

* fixed uncaught json exception in java native api gen

* cleaning up

Co-authored-by: Luis Ballabeni <[email protected]>
jimschubert added a commit that referenced this issue May 8, 2020
…-5.0

* origin/master: (78 commits)
  [powershell-experimental] : http signature authentication implementation (#6176)
  Add missing AnyType type mapping (#6196)
  remove pubspec.lock (#6208)
  Minor fixes post-release (#6204)
  [cpp][Qt5] Add the ability to pass QNetworkAccessManager as a parameter  (#6053)
  comment out dart2 test due to failure
  adds the missing typeMapping for AnyType (#6199)
  [Rust Server] Support boolean headers, and fix panic handling headers (#6056)
  update samples
  update 5.0.0 release date
  update readme with new release
  Prepare 4.3.1 release (#6187)
  Fix #6157: Updated native template to fix null async return (#6168)
  Show description when summary is missing (#6159)
  Make the array items optional (#6132)
  [aspnetcore] test petstore samples in drone.io (#6148)
  fix bearer auth in c# netcore async call (#6136)
  skip web.config for aspnetcore 3.x (#6147)
  Adds memoization and deserialization through 2 or more discriminators (#6124)
  Implement Asp.Net Core 3.0/3.1 generator (#6009) (#6025)
  ...
therve pushed a commit to DataDog/datadog-api-client-java that referenced this issue Mar 23, 2021
* Fix #6157: Updated native template to fix null async return

Should fix issue: OpenAPITools/openapi-generator#6157

* fixed uncaught json exception in java native api gen

* cleaning up

Co-authored-by: Luis Ballabeni <[email protected]>
api-clients-generation-pipeline bot pushed a commit to DataDog/datadog-api-client-java that referenced this issue Sep 8, 2021
* Fix #6157: Updated native template to fix null async return

Should fix issue: OpenAPITools/openapi-generator#6157

* fixed uncaught json exception in java native api gen

* cleaning up

Co-authored-by: Luis Ballabeni <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants