Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3497
Something went wrong while setting issue due date.
Closed
Open
Issue created 5 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

[BUG] [JAVA] okhttp-gson generates broken method in ApiClient.java

Closed

[BUG] [JAVA] okhttp-gson generates broken method in ApiClient.java

Created by: lostiniceland

Description

The current Okhttp3 - ApiClient Mustache generates a broken method. the current setHttpClient(OkHttpClient newHttpClient) copies the interceptors from the current field to the new variable, ignoring the fact that the interceptors are already present. The result is, that each call to setHttpClient duplicates the current interceptors.

Okhttp made the HttpClient immutable and provided a builder-pattern which already captures the current state.

openapi-generator version

4.0.2

Steps to reproduce
  • Configure Generator to use okhttp-gson
  • Generate some API
  • Prepare ApiClient
  • Add Interceptor apiClient.setHttpClient(apiClient.getHttpClient().newBuilder().addInterceptor(interceptor).build())
  • Repeat the previous call and check the Interceptors (the first one is now duplicated)
Suggest a fix
public ApiClient setHttpClient(OkHttpClient newHttpClient) {
   this.httpClient = newHttpClient;
}
Workaround with Groovy

We faced this problem in our Spock-Tests (Groovy) and thanks to Groovy we can bypass the setHttpClient method and set the new client directly using the @-Syntax

apiClient.@httpClient = apiClient.httpClient.newBuilder().addInterceptor(interceptor).build()

An error occurred while loading designs. Please try again.
Tasks
0
server returned results with length 5, expected length of 9

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
No estimate or time spent
Confidentiality
Not confidential
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
0
0 participants
Reference:

Menu

Explore Projects Groups Snippets