Skip to content

Commit fda1130

Browse files
committed
refactor: drop unused errorTypes map from invokeAPI
1 parent d6329df commit fda1130

5 files changed

Lines changed: 26 additions & 62 deletions

File tree

sdk/src/main/java/com/fingerprint/v4/api/FingerprintApi.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fingerprint.v4.model.BotInfoCategory;
44
import com.fingerprint.v4.model.BotInfoConfidence;
55
import com.fingerprint.v4.model.BotInfoIdentity;
6-
import com.fingerprint.v4.model.ErrorResponse;
76
import com.fingerprint.v4.model.Event;
87
import com.fingerprint.v4.model.EventSearch;
98
import com.fingerprint.v4.model.EventUpdate;
@@ -128,8 +127,6 @@ public ApiResponse<Void> deleteVisitorDataWithHttpInfo(String visitorId) throws
128127
final String localVarAccept = apiClient.selectHeaderAccept("application/json");
129128
final String localVarContentType = apiClient.selectHeaderContentType();
130129
String[] localVarAuthNames = new String[] {"bearerAuth"};
131-
final Map<String, GenericType<?>> localVarErrorTypes = new HashMap<String, GenericType<?>>();
132-
localVarErrorTypes.put("0", new GenericType<ErrorResponse>() {});
133130

134131
return apiClient.invokeAPI(
135132
"FingerprintApi.deleteVisitorData",
@@ -144,8 +141,7 @@ public ApiResponse<Void> deleteVisitorDataWithHttpInfo(String visitorId) throws
144141
localVarContentType,
145142
localVarAuthNames,
146143
null,
147-
false,
148-
localVarErrorTypes);
144+
false);
149145
}
150146

151147
public static class GetEventOptionalParams {
@@ -259,8 +255,6 @@ public ApiResponse<Event> getEventWithHttpInfo(
259255
final String localVarAccept = apiClient.selectHeaderAccept("application/json");
260256
final String localVarContentType = apiClient.selectHeaderContentType();
261257
String[] localVarAuthNames = new String[] {"bearerAuth"};
262-
final Map<String, GenericType<?>> localVarErrorTypes = new HashMap<String, GenericType<?>>();
263-
localVarErrorTypes.put("0", new GenericType<ErrorResponse>() {});
264258

265259
GenericType<Event> localVarReturnType = new GenericType<Event>() {};
266260

@@ -277,8 +271,7 @@ public ApiResponse<Event> getEventWithHttpInfo(
277271
localVarContentType,
278272
localVarAuthNames,
279273
localVarReturnType,
280-
false,
281-
localVarErrorTypes);
274+
false);
282275
}
283276

284277
public static class SearchEventsOptionalParams {
@@ -1354,8 +1347,6 @@ public ApiResponse<EventSearch> searchEventsWithHttpInfo(
13541347
final String localVarAccept = apiClient.selectHeaderAccept("application/json");
13551348
final String localVarContentType = apiClient.selectHeaderContentType();
13561349
String[] localVarAuthNames = new String[] {"bearerAuth"};
1357-
final Map<String, GenericType<?>> localVarErrorTypes = new HashMap<String, GenericType<?>>();
1358-
localVarErrorTypes.put("0", new GenericType<ErrorResponse>() {});
13591350

13601351
GenericType<EventSearch> localVarReturnType = new GenericType<EventSearch>() {};
13611352

@@ -1372,8 +1363,7 @@ public ApiResponse<EventSearch> searchEventsWithHttpInfo(
13721363
localVarContentType,
13731364
localVarAuthNames,
13741365
localVarReturnType,
1375-
false,
1376-
localVarErrorTypes);
1366+
false);
13771367
}
13781368

13791369
/**
@@ -1445,8 +1435,6 @@ public ApiResponse<Void> updateEventWithHttpInfo(String eventId, EventUpdate eve
14451435
final String localVarAccept = apiClient.selectHeaderAccept("application/json");
14461436
final String localVarContentType = apiClient.selectHeaderContentType("application/json");
14471437
String[] localVarAuthNames = new String[] {"bearerAuth"};
1448-
final Map<String, GenericType<?>> localVarErrorTypes = new HashMap<String, GenericType<?>>();
1449-
localVarErrorTypes.put("0", new GenericType<ErrorResponse>() {});
14501438

14511439
return apiClient.invokeAPI(
14521440
"FingerprintApi.updateEvent",
@@ -1461,7 +1449,6 @@ public ApiResponse<Void> updateEventWithHttpInfo(String eventId, EventUpdate eve
14611449
localVarContentType,
14621450
localVarAuthNames,
14631451
null,
1464-
false,
1465-
localVarErrorTypes);
1452+
false);
14661453
}
14671454
}

sdk/src/main/java/com/fingerprint/v4/sdk/ApiClient.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,6 @@ public File prepareDownloadFile(Response response) throws IOException {
10001000
* @param authNames The authentications to apply
10011001
* @param returnType The return type into which to deserialize the response
10021002
* @param isBodyNullable True if the body is nullable
1003-
* @param errorTypes Mapping of error codes to types into which to deserialize the response
10041003
* @return The response body in type of string
10051004
* @throws ApiException API exception
10061005
*/
@@ -1017,8 +1016,7 @@ public <T> ApiResponse<T> invokeAPI(
10171016
String contentType,
10181017
String[] authNames,
10191018
GenericType<T> returnType,
1020-
boolean isBodyNullable,
1021-
Map<String, GenericType<?>> errorTypes)
1019+
boolean isBodyNullable)
10221020
throws ApiException {
10231021

10241022
String targetURL;
@@ -1126,7 +1124,7 @@ public <T> ApiResponse<T> invokeAPI(
11261124
message,
11271125
buildResponseHeaders(response),
11281126
respBody,
1129-
deserializeErrorEntity(errorTypes, response));
1127+
deserializeErrorEntity(response));
11301128
}
11311129
} finally {
11321130
try {
@@ -1138,26 +1136,18 @@ public <T> ApiResponse<T> invokeAPI(
11381136
}
11391137
}
11401138

1139+
private static final GenericType<ErrorResponse> ERROR_GENERIC_TYPE =
1140+
new GenericType<>(ErrorResponse.class);
1141+
11411142
/**
1142-
* Deserialize the response body into an error entity based on HTTP status code.
1143-
* Looks up the error type from the errorTypes map using the response status code,
1144-
* or falls back to the "default" error type if no match is found.
1143+
* Deserialize the response body into an error entity.
11451144
*
1146-
* @param errorTypes Map of status code strings to GenericType for deserialization
11471145
* @param response The HTTP response
1148-
* @return The deserialized error entity, or null if not found or deserialization fails
1146+
* @return The deserialized error entity, or null if deserialization fails
11491147
*/
1150-
private ErrorResponse deserializeErrorEntity(
1151-
Map<String, GenericType<?>> errorTypes, Response response) {
1152-
if (errorTypes == null) {
1153-
return null;
1154-
}
1155-
GenericType<?> errorType = errorTypes.get(String.valueOf(response.getStatus()));
1156-
if (errorType == null) {
1157-
errorType = errorTypes.get("0"); // "0" is the "default" response
1158-
}
1148+
private ErrorResponse deserializeErrorEntity(Response response) {
11591149
try {
1160-
return (ErrorResponse) deserialize(response, errorType);
1150+
return deserialize(response, ERROR_GENERIC_TYPE);
11611151
} catch (Exception e) {
11621152
return null;
11631153
}
@@ -1215,8 +1205,7 @@ public <T> ApiResponse<T> invokeAPI(
12151205
contentType,
12161206
authNames,
12171207
returnType,
1218-
isBodyNullable,
1219-
null);
1208+
isBodyNullable);
12201209
}
12211210

12221211
/**

sdk/src/test/java/com/fingerprint/v4/api/FingerprintApiTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ private <T> void addMock(String operation, String path, ApiAnswerFunction<T> ans
140140
any(), // contentType
141141
any(), // authNames
142142
any(), // returnType
143-
eq(false), // isBodyNullable
144-
any() // errorTypes
143+
eq(false) // isBodyNullable
145144
);
146145
}
147146

template/libraries/jersey3/ApiClient.mustache

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12011201
* @param authNames The authentications to apply
12021202
* @param returnType The return type into which to deserialize the response
12031203
* @param isBodyNullable True if the body is nullable
1204-
* @param errorTypes Mapping of error codes to types into which to deserialize the response
12051204
* @return The response body in type of string
12061205
* @throws ApiException API exception
12071206
*/
@@ -1218,8 +1217,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12181217
String contentType,
12191218
String[] authNames,
12201219
GenericType<T> returnType,
1221-
boolean isBodyNullable,
1222-
Map<String, GenericType<?>> errorTypes)
1220+
boolean isBodyNullable)
12231221
throws ApiException {
12241222
12251223
String targetURL;
@@ -1349,7 +1347,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13491347
}
13501348
}
13511349
throw new ApiException(
1352-
response.getStatus(), message, buildResponseHeaders(response), respBody, deserializeErrorEntity(errorTypes, response));
1350+
response.getStatus(), message, buildResponseHeaders(response), respBody, deserializeErrorEntity(response));
13531351
}
13541352
} finally {
13551353
try {
@@ -1361,25 +1359,18 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13611359
}
13621360
}
13631361
1362+
private static final GenericType<ErrorResponse> ERROR_GENERIC_TYPE =
1363+
new GenericType<>(ErrorResponse.class);
1364+
13641365
/**
1365-
* Deserialize the response body into an error entity based on HTTP status code.
1366-
* Looks up the error type from the errorTypes map using the response status code,
1367-
* or falls back to the "default" error type if no match is found.
1366+
* Deserialize the response body into an error entity.
13681367
*
1369-
* @param errorTypes Map of status code strings to GenericType for deserialization
13701368
* @param response The HTTP response
1371-
* @return The deserialized error entity, or null if not found or deserialization fails
1369+
* @return The deserialized error entity, or null if deserialization fails
13721370
*/
1373-
private ErrorResponse deserializeErrorEntity(Map<String, GenericType<?>> errorTypes, Response response) {
1374-
if (errorTypes == null) {
1375-
return null;
1376-
}
1377-
GenericType<?> errorType = errorTypes.get(String.valueOf(response.getStatus()));
1378-
if (errorType == null) {
1379-
errorType = errorTypes.get("0"); // "0" is the "default" response
1380-
}
1371+
private ErrorResponse deserializeErrorEntity(Response response) {
13811372
try {
1382-
return (ErrorResponse) deserialize(response, errorType);
1373+
return deserialize(response, ERROR_GENERIC_TYPE);
13831374
} catch (Exception e) {
13841375
return null;
13851376
}
@@ -1410,7 +1401,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14101401
*/
14111402
@Deprecated
14121403
public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, GenericType<T> returnType, boolean isBodyNullable) throws ApiException {
1413-
return invokeAPI(null, path, method, queryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType, isBodyNullable, null);
1404+
return invokeAPI(null, path, method, queryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType, isBodyNullable);
14141405
}
14151406
14161407
/**

template/libraries/jersey3/api.mustache

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,14 @@ public class {{classname}} {
275275
final String localVarAccept = apiClient.selectHeaderAccept({{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}});
276276
final String localVarContentType = apiClient.selectHeaderContentType({{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}});
277277
String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} };
278-
final Map<String, GenericType<?>> localVarErrorTypes = new HashMap<String, GenericType<?>>();
279-
localVarErrorTypes.put("0", new GenericType<ErrorResponse>() {});
280278

281279
{{#returnType}}
282280
GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {};
283281

284282
{{/returnType}}
285283
return apiClient.invokeAPI("{{classname}}.{{operationId}}", localVarPath, "{{httpMethod}}", localVarQueryParams, localVarPostBody,
286284
localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType,
287-
localVarAuthNames, {{#returnType}}localVarReturnType{{/returnType}}{{^returnType}}null{{/returnType}}, {{#bodyParam}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/bodyParam}}{{^bodyParam}}false{{/bodyParam}}, localVarErrorTypes);
285+
localVarAuthNames, {{#returnType}}localVarReturnType{{/returnType}}{{^returnType}}null{{/returnType}}, {{#bodyParam}}{{#isNullable}}true{{/isNullable}}{{^isNullable}}false{{/isNullable}}{{/bodyParam}}{{^bodyParam}}false{{/bodyParam}});
288286
}
289287
{{/operation}}
290288
}

0 commit comments

Comments
 (0)