Skip to content

[Java][OkHttp] Generate API getters in ApiClient.java #12249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package {{invokerPackage}};

import {{apiPackage}}.*;
{{#dynamicOperations}}
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
Expand Down Expand Up @@ -1755,4 +1756,15 @@ public class ApiClient {
// empty http request body
return "";
}

{{#apiInfo}}{{#apis}}
/**
* Get an instance of {{classname}}
*
* @return An instance of {{classname}}
*/
public {{classname}} get{{classname}}() {
return new {{classname}}(this);
}
{{/apis}}{{/apiInfo}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class Example {
{{/authMethods}}
{{/hasAuthMethods}}

{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
{{{classname}}} apiInstance = defaultClient.get{{{classname}}}();
{{#allParams}}
{{{dataType}}} {{{paramName}}} = {{{example}}}; // {{{dataType}}} | {{{description}}}
{{/allParams}}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/others/java/okhttp-gson-streaming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Example {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:8082");

PingApi apiInstance = new PingApi(defaultClient);
PingApi apiInstance = defaultClient.getPingApi();
SomeObj someObj = new SomeObj(); // SomeObj |
try {
SomeObj result = apiInstance.postPing(someObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.openapitools.client;

import org.openapitools.client.api.*;
import okhttp3.*;
import okhttp3.internal.http.HttpMethod;
import okhttp3.internal.tls.OkHostnameVerifier;
Expand Down Expand Up @@ -1479,4 +1480,15 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
// empty http request body
return "";
}


/**
* Get an instance of PingApi
*
* @return An instance of PingApi
*/
public PingApi getPingApi() {
return new PingApi(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Example {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

AnotherFakeApi apiInstance = new AnotherFakeApi(defaultClient);
AnotherFakeApi apiInstance = defaultClient.getAnotherFakeApi();
Client body = new Client(); // Client | client model
try {
Client result = apiInstance.call123testSpecialTags(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.openapitools.client;

import org.openapitools.client.api.*;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
Expand Down Expand Up @@ -1626,4 +1627,60 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
// empty http request body
return "";
}


/**
* Get an instance of AnotherFakeApi
*
* @return An instance of AnotherFakeApi
*/
public AnotherFakeApi getAnotherFakeApi() {
return new AnotherFakeApi(this);
}

/**
* Get an instance of FakeApi
*
* @return An instance of FakeApi
*/
public FakeApi getFakeApi() {
return new FakeApi(this);
}

/**
* Get an instance of FakeClassnameTags123Api
*
* @return An instance of FakeClassnameTags123Api
*/
public FakeClassnameTags123Api getFakeClassnameTags123Api() {
return new FakeClassnameTags123Api(this);
}

/**
* Get an instance of PetApi
*
* @return An instance of PetApi
*/
public PetApi getPetApi() {
return new PetApi(this);
}

/**
* Get an instance of StoreApi
*
* @return An instance of StoreApi
*/
public StoreApi getStoreApi() {
return new StoreApi(this);
}

/**
* Get an instance of UserApi
*
* @return An instance of UserApi
*/
public UserApi getUserApi() {
return new UserApi(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Example {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

AnotherFakeApi apiInstance = new AnotherFakeApi(defaultClient);
AnotherFakeApi apiInstance = defaultClient.getAnotherFakeApi();
Client body = new Client(); // Client | client model
try {
Client result = apiInstance.call123testSpecialTags(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.openapitools.client;

import org.openapitools.client.api.*;
import okhttp3.*;
import okhttp3.internal.http.HttpMethod;
import okhttp3.internal.tls.OkHostnameVerifier;
Expand Down Expand Up @@ -1558,4 +1559,60 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
// empty http request body
return "";
}


/**
* Get an instance of AnotherFakeApi
*
* @return An instance of AnotherFakeApi
*/
public AnotherFakeApi getAnotherFakeApi() {
return new AnotherFakeApi(this);
}

/**
* Get an instance of FakeApi
*
* @return An instance of FakeApi
*/
public FakeApi getFakeApi() {
return new FakeApi(this);
}

/**
* Get an instance of FakeClassnameTags123Api
*
* @return An instance of FakeClassnameTags123Api
*/
public FakeClassnameTags123Api getFakeClassnameTags123Api() {
return new FakeClassnameTags123Api(this);
}

/**
* Get an instance of PetApi
*
* @return An instance of PetApi
*/
public PetApi getPetApi() {
return new PetApi(this);
}

/**
* Get an instance of StoreApi
*
* @return An instance of StoreApi
*/
public StoreApi getStoreApi() {
return new StoreApi(this);
}

/**
* Get an instance of UserApi
*
* @return An instance of UserApi
*/
public UserApi getUserApi() {
return new UserApi(this);
}

}
2 changes: 1 addition & 1 deletion samples/client/petstore/java/okhttp-gson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class Example {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

AnotherFakeApi apiInstance = new AnotherFakeApi(defaultClient);
AnotherFakeApi apiInstance = defaultClient.getAnotherFakeApi();
Client client = new Client(); // Client | client model
try {
Client result = apiInstance.call123testSpecialTags(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.openapitools.client;

import org.openapitools.client.api.*;
import okhttp3.*;
import okhttp3.internal.http.HttpMethod;
import okhttp3.internal.tls.OkHostnameVerifier;
Expand Down Expand Up @@ -1577,4 +1578,69 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
// empty http request body
return "";
}


/**
* Get an instance of AnotherFakeApi
*
* @return An instance of AnotherFakeApi
*/
public AnotherFakeApi getAnotherFakeApi() {
return new AnotherFakeApi(this);
}

/**
* Get an instance of DefaultApi
*
* @return An instance of DefaultApi
*/
public DefaultApi getDefaultApi() {
return new DefaultApi(this);
}

/**
* Get an instance of FakeApi
*
* @return An instance of FakeApi
*/
public FakeApi getFakeApi() {
return new FakeApi(this);
}

/**
* Get an instance of FakeClassnameTags123Api
*
* @return An instance of FakeClassnameTags123Api
*/
public FakeClassnameTags123Api getFakeClassnameTags123Api() {
return new FakeClassnameTags123Api(this);
}

/**
* Get an instance of PetApi
*
* @return An instance of PetApi
*/
public PetApi getPetApi() {
return new PetApi(this);
}

/**
* Get an instance of StoreApi
*
* @return An instance of StoreApi
*/
public StoreApi getStoreApi() {
return new StoreApi(this);
}

/**
* Get an instance of UserApi
*
* @return An instance of UserApi
*/
public UserApi getUserApi() {
return new UserApi(this);
}

}