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 @@ -33,6 +33,7 @@ import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;
import java.util.Optional;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -76,7 +77,7 @@ public class ApiClient {
}

private HttpHeaders defaultHeaders = new HttpHeaders();

private String basePath = "{{basePath}}";

private final WebClient webClient;
Expand All @@ -87,28 +88,30 @@ public class ApiClient {

public ApiClient() {
this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), this.dateFormat);

init();
this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
this.init();
}

public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format);
}

public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
}

private ApiClient(WebClient webClient, DateFormat format) {
this.webClient = webClient;
this.dateFormat = format;

init();
this.init();
}

public DateFormat createDefaultDateFormat() {
DateFormat dateFormat = new RFC3339DateFormat();
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat;
}

protected void init() {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
Expand Down Expand Up @@ -136,7 +139,7 @@ public class ApiClient {
return webClient.build();
}


/**
* Get the current base path
* @return String the base path
Expand Down Expand Up @@ -589,7 +592,7 @@ public class ApiClient {
auth.applyToParams(queryParams, headerParams);
}
}

private class ApiClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
private final Log log = LogFactory.getLog(ApiClientHttpRequestInterceptor.class);

Expand Down Expand Up @@ -628,7 +631,7 @@ public class ApiClient {
builder.setLength(builder.length() - 1); // Get rid of trailing comma
return builder.toString();
}

private String bodyToString(InputStream body) throws IOException {
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Flux;
import java.util.Optional;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -76,7 +77,7 @@ private String collectionToString(Collection<? extends CharSequence> collection)
}

private HttpHeaders defaultHeaders = new HttpHeaders();

private String basePath = "http://petstore.swagger.io:80/v2";

private final WebClient webClient;
Expand All @@ -87,28 +88,30 @@ private String collectionToString(Collection<? extends CharSequence> collection)

public ApiClient() {
this.dateFormat = createDefaultDateFormat();
this.webClient = buildWebClient(new ObjectMapper(), this.dateFormat);

init();
this.webClient = buildWebClient(new ObjectMapper(), dateFormat);
this.init();
}

public ApiClient(ObjectMapper mapper, DateFormat format) {
this(buildWebClient(mapper.copy(), format), format);
}

public ApiClient(WebClient webClient, ObjectMapper mapper, DateFormat format) {
this(Optional.ofNullable(webClient).orElseGet(() ->buildWebClient(mapper.copy(), format)), format);
}

private ApiClient(WebClient webClient, DateFormat format) {
this.webClient = webClient;
this.dateFormat = format;

init();
this.init();
}

public DateFormat createDefaultDateFormat() {
DateFormat dateFormat = new RFC3339DateFormat();
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat;
}

protected void init() {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
Expand Down Expand Up @@ -137,7 +140,7 @@ public static WebClient buildWebClient(ObjectMapper mapper, DateFormat dateForma
return webClient.build();
}


/**
* Get the current base path
* @return String the base path
Expand Down Expand Up @@ -590,7 +593,7 @@ private void updateParamsForAuth(String[] authNames, MultiValueMap<String, Strin
auth.applyToParams(queryParams, headerParams);
}
}

private class ApiClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
private final Log log = LogFactory.getLog(ApiClientHttpRequestInterceptor.class);

Expand Down Expand Up @@ -629,7 +632,7 @@ private String headersToString(HttpHeaders headers) {
builder.setLength(builder.length() - 1); // Get rid of trailing comma
return builder.toString();
}

private String bodyToString(InputStream body) throws IOException {
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
Expand Down