forked from loafle/openapi-generator-original
[Java][Client] Generate servers for okhttp-gson (#14179)
* [Java][Client] Generate servers for okhttp-gson * Update sample tests
This commit is contained in:
@@ -66,6 +66,58 @@ import org.openapitools.client.auth.OAuthFlow;
|
||||
public class ApiClient {
|
||||
|
||||
private String basePath = "http://petstore.swagger.io:80/v2";
|
||||
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"http://{server}.swagger.io:{port}/v2",
|
||||
"petstore server",
|
||||
new HashMap<String, ServerVariable>() {{
|
||||
put("server", new ServerVariable(
|
||||
"No description provided",
|
||||
"petstore",
|
||||
new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"petstore",
|
||||
"qa-petstore",
|
||||
"dev-petstore"
|
||||
)
|
||||
)
|
||||
));
|
||||
put("port", new ServerVariable(
|
||||
"No description provided",
|
||||
"80",
|
||||
new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"80",
|
||||
"8080"
|
||||
)
|
||||
)
|
||||
));
|
||||
}}
|
||||
),
|
||||
new ServerConfiguration(
|
||||
"https://localhost:8080/{version}",
|
||||
"The local server",
|
||||
new HashMap<String, ServerVariable>() {{
|
||||
put("version", new ServerVariable(
|
||||
"No description provided",
|
||||
"v2",
|
||||
new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"v1",
|
||||
"v2"
|
||||
)
|
||||
)
|
||||
));
|
||||
}}
|
||||
),
|
||||
new ServerConfiguration(
|
||||
"https://127.0.0.1/no_variable",
|
||||
"The local server without variables",
|
||||
new HashMap<String, ServerVariable>()
|
||||
)
|
||||
));
|
||||
protected Integer serverIndex = 0;
|
||||
protected Map<String, String> serverVariables = null;
|
||||
private boolean debugging = false;
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
@@ -242,6 +294,33 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<ServerConfiguration> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public ApiClient setServers(List<ServerConfiguration> servers) {
|
||||
this.servers = servers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getServerIndex() {
|
||||
return serverIndex;
|
||||
}
|
||||
|
||||
public ApiClient setServerIndex(Integer serverIndex) {
|
||||
this.serverIndex = serverIndex;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getServerVariables() {
|
||||
return serverVariables;
|
||||
}
|
||||
|
||||
public ApiClient setServerVariables(Map<String, String> serverVariables) {
|
||||
this.serverVariables = serverVariables;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HTTP client
|
||||
*
|
||||
@@ -1294,7 +1373,18 @@ public class ApiClient {
|
||||
if (baseUrl != null) {
|
||||
url.append(baseUrl).append(path);
|
||||
} else {
|
||||
url.append(basePath).append(path);
|
||||
String baseURL;
|
||||
if (serverIndex != null) {
|
||||
if (serverIndex < 0 || serverIndex >= servers.size()) {
|
||||
throw new ArrayIndexOutOfBoundsException(String.format(
|
||||
"Invalid index %d when selecting the host settings. Must be less than %d", serverIndex, servers.size()
|
||||
));
|
||||
}
|
||||
baseURL = servers.get(serverIndex).URL(serverVariables);
|
||||
} else {
|
||||
baseURL = basePath;
|
||||
}
|
||||
url.append(baseURL).append(path);
|
||||
}
|
||||
|
||||
if (queryParams != null && !queryParams.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user