Skip to content

Commit

Permalink
Update client
Browse files Browse the repository at this point in the history
  • Loading branch information
croct-bot committed Apr 1, 2024
1 parent 444a91c commit b6cc776
Show file tree
Hide file tree
Showing 74 changed files with 452 additions and 1,729 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
matrix:
java: [ '8' ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0-SNAPSHOT
7.5.0-SNAPSHOT
13 changes: 10 additions & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ paths:
description: Request error
tags:
- export
x-accepts: application/json
x-accepts:
- application/json
/session:
get:
operationId: exportSessions
Expand Down Expand Up @@ -135,7 +136,8 @@ paths:
description: Request error
tags:
- export
x-accepts: application/json
x-accepts:
- application/json
/user:
get:
operationId: exportUsers
Expand Down Expand Up @@ -188,7 +190,8 @@ paths:
description: Request error
tags:
- export
x-accepts: application/json
x-accepts:
- application/json
components:
parameters:
WindowStart:
Expand Down Expand Up @@ -266,6 +269,10 @@ components:
schemas:
ApiProblem:
additionalProperties: {}
example:
details: details
title: title
type: http://example.com/aeiou
properties:
title:
type: string
Expand Down
15 changes: 7 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemProperties>
<systemPropertyVariables>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
</systemPropertyVariables>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<threadCount>10</threadCount>
Expand Down Expand Up @@ -377,13 +377,12 @@
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-annotations-version>1.6.6</swagger-annotations-version>
<jersey-version>2.35</jersey-version>
<jackson-version>2.13.4</jackson-version>
<jackson-databind-version>2.13.4.2</jackson-databind-version>
<jackson-databind-nullable-version>0.2.4</jackson-databind-nullable-version>
<jersey-version>2.37</jersey-version>
<jackson-version>2.15.2</jackson-version>
<jackson-databind-version>2.15.2</jackson-databind-version>
<jackson-databind-nullable-version>0.2.6</jackson-databind-nullable-version>
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
<junit-version>5.8.2</junit-version>
<junit-version>5.10.0</junit-version>
<spotless.version>2.21.0</spotless.version>
</properties>
</project>
147 changes: 79 additions & 68 deletions src/main/java/com/croct/client/export/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,22 @@
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.glassfish.jersey.logging.LoggingFeature;
import java.util.AbstractMap.SimpleEntry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.time.OffsetDateTime;

import java.net.URLEncoder;
Expand All @@ -66,37 +70,38 @@
/**
* <p>ApiClient class.</p>
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.5.0-SNAPSHOT")
public class ApiClient extends JavaTimeFormatter {
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
private static final Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$");

protected Map<String, String> defaultHeaderMap = new HashMap<>();
protected Map<String, String> defaultCookieMap = new HashMap<>();
protected String basePath = "https://api.croct.io/export";
protected String userAgent;
private static final Logger log = Logger.getLogger(ApiClient.class.getName());

protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
new ServerConfiguration(
"https://api.croct.io/export",
"Production endpoint",
new HashMap<String, ServerVariable>()
),
new ServerConfiguration(
"https://api.test.croct.io/export",
"Staging endpoint",
new HashMap<String, ServerVariable>()
),
new ServerConfiguration(
"http://localhost:4000",
"Local development endpoint",
new HashMap<String, ServerVariable>()
)
protected List<ServerConfiguration> servers = new ArrayList<>(Arrays.asList(
new ServerConfiguration(
"https://api.croct.io/export",
"Production endpoint",
new LinkedHashMap<>()
),
new ServerConfiguration(
"https://api.test.croct.io/export",
"Staging endpoint",
new LinkedHashMap<>()
),
new ServerConfiguration(
"http://localhost:4000",
"Local development endpoint",
new LinkedHashMap<>()
)
));
protected Integer serverIndex = 0;
protected Map<String, String> serverVariables = null;
protected Map<String, List<ServerConfiguration>> operationServers = new HashMap<String, List<ServerConfiguration>>() {{
}};
protected Map<String, Integer> operationServerIndex = new HashMap<String, Integer>();
protected Map<String, Map<String, String>> operationServerVariables = new HashMap<String, Map<String, String>>();
protected Map<String, List<ServerConfiguration>> operationServers = new HashMap<>();
protected Map<String, Integer> operationServerIndex = new HashMap<>();
protected Map<String, Map<String, String>> operationServerVariables = new HashMap<>();
protected boolean debugging = false;
protected ClientConfig clientConfig;
protected int connectionTimeout = 0;
Expand Down Expand Up @@ -133,7 +138,7 @@ public ApiClient(Map<String, Authentication> authMap) {
setUserAgent("Croct-Client/{version}/java");

// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications = new HashMap<>();
Authentication auth = null;
if (authMap != null) {
auth = authMap.get("ApiKeyAuth");
Expand All @@ -147,7 +152,7 @@ public ApiClient(Map<String, Authentication> authMap) {
authentications = Collections.unmodifiableMap(authentications);

// Setup authentication lookup (key: authentication alias, value: authentication name)
authenticationLookup = new HashMap<String, String>();
authenticationLookup = new HashMap<>();
}

/**
Expand Down Expand Up @@ -347,9 +352,10 @@ public ApiClient configureApiKeys(Map<String, String> secrets) {
if (auth instanceof ApiKeyAuth) {
String name = authEntry.getKey();
// respect x-auth-id-alias property
name = authenticationLookup.containsKey(name) ? authenticationLookup.get(name) : name;
if (secrets.containsKey(name)) {
((ApiKeyAuth) auth).setApiKey(secrets.get(name));
name = authenticationLookup.getOrDefault(name, name);
String secret = secrets.get(name);
if (secret != null) {
((ApiKeyAuth) auth).setApiKey(secret);
}
}
}
Expand Down Expand Up @@ -627,7 +633,7 @@ public String parameterToString(Object param) {
* @return List of pairs
*/
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
List<Pair> params = new ArrayList<Pair>();
List<Pair> params = new ArrayList<>();

// preconditions
if (name == null || name.isEmpty() || value == null) return params;
Expand Down Expand Up @@ -686,14 +692,13 @@ public List<Pair> parameterToPairs(String collectionFormat, String name, Object
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* "* / *" is also default to JSON
* "*{@literal /}*" is also considered JSON by this method.
*
* @param mime MIME
* @return True if the MIME type is JSON
*/
public boolean isJsonMime(String mime) {
String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
return mime != null && (mime.equals("*/*") || JSON_MIME_PATTERN.matcher(mime).matches());
}

/**
Expand All @@ -705,8 +710,8 @@ public boolean isJsonMime(String mime) {
* @return The Accept header to use. If the given array is empty,
* null will be returned (not to set the Accept header explicitly).
*/
public String selectHeaderAccept(String[] accepts) {
if (accepts.length == 0) {
public String selectHeaderAccept(String... accepts) {
if (accepts == null || accepts.length == 0) {
return null;
}
for (String accept : accepts) {
Expand All @@ -726,8 +731,8 @@ public String selectHeaderAccept(String[] accepts) {
* @return The Content-Type header to use. If the given array is empty,
* JSON will be used.
*/
public String selectHeaderContentType(String[] contentTypes) {
if (contentTypes.length == 0) {
public String selectHeaderContentType(String... contentTypes) {
if (contentTypes == null || contentTypes.length == 0) {
return "application/json";
}
for (String contentType : contentTypes) {
Expand Down Expand Up @@ -771,7 +776,17 @@ public Entity<?> serialize(Object obj, Map<String, Object> formParams, String co
File file = (File) param.getValue();
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey())
.fileName(file.getName()).size(file.length()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, MediaType.APPLICATION_OCTET_STREAM_TYPE));

// Attempt to probe the content type for the file so that the form part is more correctly
// and precisely identified, but fall back to application/octet-stream if that fails.
MediaType type;
try {
type = MediaType.valueOf(Files.probeContentType(file.toPath()));
} catch (IOException | IllegalArgumentException e) {
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
}

multiPart.bodyPart(new FormDataBodyPart(contentDisp, file, type));
} else {
FormDataContentDisposition contentDisp = FormDataContentDisposition.name(param.getKey()).build();
multiPart.bodyPart(new FormDataBodyPart(contentDisp, parameterToString(param.getValue())));
Expand Down Expand Up @@ -865,11 +880,6 @@ public <T> T deserialize(Response response, GenericType<T> returnType) throws Ap
return file;
}

String contentType = null;
List<Object> contentTypes = response.getHeaders().get("Content-Type");
if (contentTypes != null && !contentTypes.isEmpty())
contentType = String.valueOf(contentTypes.get(0));

// read the entity stream multiple times
response.bufferEntity();

Expand Down Expand Up @@ -971,14 +981,11 @@ public <T> ApiResponse<T> invokeAPI(
boolean isBodyNullable)
throws ApiException {

// Not using `.target(targetURL).path(path)` below,
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
String targetURL;
if (serverIndex != null && operationServers.containsKey(operation)) {
Integer index = operationServerIndex.containsKey(operation) ? operationServerIndex.get(operation) : serverIndex;
Map<String, String> variables = operationServerVariables.containsKey(operation) ?
operationServerVariables.get(operation) : serverVariables;
List<ServerConfiguration> serverConfigurations = operationServers.get(operation);
List<ServerConfiguration> serverConfigurations;
if (serverIndex != null && (serverConfigurations = operationServers.get(operation)) != null) {
int index = operationServerIndex.getOrDefault(operation, serverIndex).intValue();
Map<String, String> variables = operationServerVariables.getOrDefault(operation, serverVariables);
if (index < 0 || index >= serverConfigurations.size()) {
throw new ArrayIndexOutOfBoundsException(
String.format(
Expand All @@ -989,6 +996,8 @@ public <T> ApiResponse<T> invokeAPI(
} else {
targetURL = this.basePath + path;
}
// Not using `.target(targetURL).path(path)` below,
// to support (constant) query string in `path`, e.g. "/posts?draft=1"
WebTarget target = httpClient.target(targetURL);

if (queryParams != null) {
Expand All @@ -999,11 +1008,10 @@ public <T> ApiResponse<T> invokeAPI(
}
}

Invocation.Builder invocationBuilder;
Invocation.Builder invocationBuilder = target.request();

if (accept != null) {
invocationBuilder = target.request().accept(accept);
} else {
invocationBuilder = target.request();
invocationBuilder = invocationBuilder.accept(accept);
}

for (Entry<String, String> entry : cookieParams.entrySet()) {
Expand All @@ -1026,15 +1034,17 @@ public <T> ApiResponse<T> invokeAPI(
Map<String, String> allHeaderParams = new HashMap<>(defaultHeaderMap);
allHeaderParams.putAll(headerParams);

// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
if (authNames != null) {
// update different parameters (e.g. headers) for authentication
updateParamsForAuth(
authNames,
queryParams,
allHeaderParams,
cookieParams,
null,
method,
target.getUri());
}

for (Entry<String, String> entry : allHeaderParams.entrySet()) {
String value = entry.getValue();
Expand All @@ -1048,10 +1058,11 @@ public <T> ApiResponse<T> invokeAPI(
try {
response = sendRequest(method, invocationBuilder, entity);

int statusCode = response.getStatusInfo().getStatusCode();
final int statusCode = response.getStatusInfo().getStatusCode();

Map<String, List<String>> responseHeaders = buildResponseHeaders(response);

if (response.getStatusInfo() == Status.NO_CONTENT) {
if (statusCode == Status.NO_CONTENT.getStatusCode()) {
return new ApiResponse<T>(statusCode, responseHeaders);
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
if (returnType == null) {
Expand Down Expand Up @@ -1117,8 +1128,8 @@ protected Client buildHttpClient() {
clientConfig = getDefaultClientConfig();

ClientBuilder clientBuilder = ClientBuilder.newBuilder();
customizeClientBuilder(clientBuilder);
clientBuilder = clientBuilder.withConfig(clientConfig);
customizeClientBuilder(clientBuilder);
return clientBuilder.build();
}

Expand Down Expand Up @@ -1205,10 +1216,10 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
* @return a {@link java.util.Map} of response headers.
*/
protected Map<String, List<String>> buildResponseHeaders(Response response) {
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
Map<String, List<String>> responseHeaders = new HashMap<>();
for (Entry<String, List<Object>> entry: response.getHeaders().entrySet()) {
List<Object> values = entry.getValue();
List<String> headers = new ArrayList<String>();
List<String> headers = new ArrayList<>();
for (Object o : values) {
headers.add(String.valueOf(o));
}
Expand Down
Loading

0 comments on commit b6cc776

Please sign in to comment.