swagger-api / swagger-api/swagger-codegen

[JAVA] Feature request: Introduce API client interface

Open
#8,949 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

At the moment Swagger generates concrete implementation of ApiClient which is then passed to my actual API client. It would be beneficial to introduce ApiClientInterface that the custom client then accepts, which would allow the developer to write integration tests against Mock APIs.

At the moment, the only option is to generate stub server with dummy data and change the endpoint when doing integration tests.

Suggest a fix/enhancement
public class ApiClient implements ApiInterface {
    /** same as now **/
}

public class DefaultApi {
    private ApiInterface apiClient;

    public DefaultApi(ApiInterface apiClient) {
        this.apiClient = apiClient;
    }
    /** same as now **/
}

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

No files or tests are named. Start by locating the Java generator entry points and the templates that produce ApiClient and DefaultApi, then check how generated clients are wired together. Done means generated Java clients can accept an API client interface so integration tests can substitute mock APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.