swagger-api / swagger-api/swagger-codegen

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

Open
#6,497 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Java help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Java client's ApiClient.setDebugging(boolean) method and Configuration.getDefaultClient(), then reproduce the behavior using any generated client and HTTP traffic. Verify the existing HTTP client interceptors before and after enabling debugging; done means passing true reliably enables request and response logging even when debugging was already true.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.