OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.36k stars 6.46k forks source link

[Java] [Android] Jersey2 library request/issue - suppress warning log in android #617

Open mintu19 opened 6 years ago

mintu19 commented 6 years ago

I am continuing the issue i have filed at Swagger-Codegen. I think that similar approach can be applied to here as well (as i understand this is fork of swagger). I have not tried it with latest release. I am creating this issue here as well for reference to feature.

Description

When I generate client for java using Jersey 2 library and use it with both java and android project (which works in android), there are warning thrown by client because of use of java.awt.* class in jersey unsupported by Android. Although these are just warnings but there are way to suppress such warnings. (and maybe make jersey2 client library available for android platform?)

The main purpose of using jersey client in Android is to support circular dependency json sent by server (Jsog Jackson)

Swagger-codegen version

2.3.1, older one (with no version command) I guess this will apply to openAPI generators as well...

Suggest a fix/enhancement

The way to suppress those warnings in logs is to add a feature to client that let hk2 not search for non available files.

Sample code for feature (that i am using with generated code)

import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import org.glassfish.hk2.api.Descriptor;
import org.glassfish.hk2.api.Filter;
import org.glassfish.hk2.utilities.binding.AbstractBinder;

/**
 *
 * @author akshit
 */
public class AndroidFriendlyFeature implements Feature {
    @Override
    public boolean configure(FeatureContext context) {
      context.register(new AbstractBinder() {
          @Override
          protected void configure() {
              addUnbindFilter(new Filter() {
                  @Override
                  public boolean matches(Descriptor d) {
                      String implClass = d.getImplementation();
                      return implClass.startsWith("org.glassfish.jersey.message.internal.DataSource")
                       || implClass.startsWith("org.glassfish.jersey.message.internal.RenderedImage");
                  }
              });
          }
      });
      return true;
    }
}

then add it to client on ApiClient.java buildHttpClient Method

clientConfig.register(AndroidFriendlyFeature.class);
wing328 commented 6 years ago

@mintu19 thanks for reporting the issue. Have you considered using other Java/Android clients (e.g. Retrofit2)?

Have you reported this issue to Jersey2 library owner (https://jersey.github.io/)?

mintu19 commented 6 years ago

I had tired others clients but these clients do not have option to resolve circular dependency with jackson circular json response. Only jackson jersey provides such features as much as i know of. No i haven't filed this issue under jersey team. I am sure problem is that android doesn't provide few of classes of JDK.

That's why its a solution to bridge andoird and jackson and remove warnings/errors.