Skip to content

[JAVA] ApiClient.setDebugging(boolean debug) fails to add LoggingInterceptors to HTTP client when its debugging field is already true #6497

@jcasey23

Description

@jcasey23
Description

Here is the code for the ApiClient.setDebugging method:

public ApiClient setDebugging(boolean debugging) {
if (debugging != this.debugging) {
if (debugging) {
loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(Level.BODY);
httpClient.interceptors().add(loggingInterceptor);
} else {
httpClient.interceptors().remove(loggingInterceptor);
loggingInterceptor = null;
}
}
this.debugging = debugging;
return this;
}

Configuration.getDefaultClient() returns an ApiClient instance in which "debugging" is already set to true. When the "setDebugging" method is called, passing the boolean true, the method fails to add the LoggingInterceptors to the HTTP client and HTTP debugging is disabled.

Swagger-codegen version

I generated the Java client from the master branch, which I believe was 2.3.0 at the time. The same code for the setDebugging method is present in version 2.2.1, so this is not a regression (from that point at least).

Command line used for generation

java -jar swagger-codegen-cli-2.3.0.jar generate -i api.yaml -l java -o SwarmApi

YAML file

For copyright reasons I cannot include the api.yaml file I was using.

Steps to reproduce
  1. Generate the JAVA client jar for any api.yaml file.
  2. Using the generated code, get an instance of the default API client using Configuration.getDefaultClient().
  3. Call the "setDebugging" method on the client instance passing the boolean argument true.
  4. Using the client instance, exercise any test code that involves HTTP traffic between the client and a server.
  5. Note that the send-receive traffic is not included in the test output.
Related issues/PRs

Not that I could find.

Suggest a fix/enhancement

When the boolean "true" is passed to the setDebugging method, interrogate the HTTP client to determine whether LogginInterceptors have already been added or not. If not, then add them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions