swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.94k stars 6.03k forks source link

[JAVA] Feature request: Introduce API client interface #8949

Open Shmarkus opened 5 years ago

Shmarkus commented 5 years ago
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 **/
}
jonfreedman commented 5 years ago

I think this redesign would be very beneficial - when I generate a Java client I want the model classes and some mapping between model and api endpoints. What I don't want is a load of non-applicable choices around authentication because I manage that outside the generated code.