Skip to content
Merged
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 @@ -42,10 +42,12 @@ import java.util.Optional;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -89,6 +91,33 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
protected final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();

protected String basePath = "{{basePath}}";
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>({{#servers}}{{#-first}}Arrays.asList(
{{/-first}} new ServerConfiguration(
"{{{url}}}",
"{{{description}}}{{^description}}No description provided{{/description}}",
new HashMap<String, ServerVariable>(){{#variables}}{{#-first}} {{
{{/-first}} put("{{{name}}}", new ServerVariable(
"{{{description}}}{{^description}}No description provided{{/description}}",
"{{{defaultValue}}}",
new HashSet<String>(
{{#enumValues}}
{{#-first}}
Arrays.asList(
{{/-first}}
"{{{.}}}"{{^-last}},{{/-last}}
{{#-last}}
)
{{/-last}}
{{/enumValues}}
)
));
{{#-last}}
}}{{/-last}}{{/variables}}
){{^-last}},{{/-last}}
{{#-last}}
){{/-last}}{{/servers}});
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;

protected final RestClient restClient;
protected final DateFormat dateFormat;
Expand Down Expand Up @@ -219,6 +248,34 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
*/
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
this.serverIndex = null;
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;
}

Expand Down Expand Up @@ -659,7 +716,19 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
MediaType contentType, String[] authNames) {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);

final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(basePath).path(path);
String baseUrl = basePath;
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);
}

final UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString(baseUrl)
.path(path);

String finalUri = builder.build(false).toUriString();
Map<String, Object> uriParams = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -76,6 +78,15 @@ protected String collectionToString(Collection<?> collection) {
protected final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();

protected String basePath = "http://localhost:3000";
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
new ServerConfiguration(
"http://localhost:3000",
"No description provided",
new HashMap<String, ServerVariable>()
)
));
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;

protected final RestClient restClient;
protected final DateFormat dateFormat;
Expand Down Expand Up @@ -188,6 +199,34 @@ public String getBasePath() {
*/
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
this.serverIndex = null;
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;
}

Expand Down Expand Up @@ -612,7 +651,19 @@ protected RestClient.RequestBodySpec prepareRequest(String path, HttpMethod meth
MediaType contentType, String[] authNames) {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);

final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(basePath).path(path);
String baseUrl = basePath;
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);
}

final UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString(baseUrl)
.path(path);

String finalUri = builder.build(false).toUriString();
Map<String, Object> uriParams = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -76,6 +78,15 @@ protected String collectionToString(Collection<?> collection) {
protected final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();

protected String basePath = "http://localhost:8080";
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
new ServerConfiguration(
"http://localhost:8080",
"Localhost, used when testing",
new HashMap<String, ServerVariable>()
)
));
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;

protected final RestClient restClient;
protected final DateFormat dateFormat;
Expand Down Expand Up @@ -187,6 +198,34 @@ public String getBasePath() {
*/
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
this.serverIndex = null;
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;
}

Expand Down Expand Up @@ -611,7 +650,19 @@ protected RestClient.RequestBodySpec prepareRequest(String path, HttpMethod meth
MediaType contentType, String[] authNames) {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);

final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(basePath).path(path);
String baseUrl = basePath;
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);
}

final UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString(baseUrl)
.path(path);

String finalUri = builder.build(false).toUriString();
Map<String, Object> uriParams = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -76,6 +78,15 @@ protected String collectionToString(Collection<?> collection) {
protected final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();

protected String basePath = "http://localhost";
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
new ServerConfiguration(
"",
"No description provided",
new HashMap<String, ServerVariable>()
)
));
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;

protected final RestClient restClient;
protected final DateFormat dateFormat;
Expand Down Expand Up @@ -186,6 +197,34 @@ public String getBasePath() {
*/
public ApiClient setBasePath(String basePath) {
this.basePath = basePath;
this.serverIndex = null;
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;
}

Expand Down Expand Up @@ -610,7 +649,19 @@ protected RestClient.RequestBodySpec prepareRequest(String path, HttpMethod meth
MediaType contentType, String[] authNames) {
updateParamsForAuth(authNames, queryParams, headerParams, cookieParams);

final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(basePath).path(path);
String baseUrl = basePath;
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);
}

final UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString(baseUrl)
.path(path);

String finalUri = builder.build(false).toUriString();
Map<String, Object> uriParams = new HashMap<>();
Expand Down
Loading
Loading