Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][okhttp-gson] Improve errorObjectType to avoid regression #12131

Merged
merged 1 commit into from
Apr 14, 2022
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 @@ -327,14 +327,20 @@ public class {{classname}} {
public{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}private{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-streaming}} InputStream {{operationId}}WithHttpInfo({{#allParams}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException {
okhttp3.Call localVarCall = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null);
{{#returnType}}
{{#errorObjectType}}
try {
Type localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<{{{errorObjectType}}}{{^errorObjectType}}{{{returnType}}}{{/errorObjectType}}>(){}.getType()));
e.setErrorObjectType(new GenericType<{{{errorObjectType}}}{{^errorObjectType}}{{{returnType}}}{{/errorObjectType}}>(){});
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<{{{errorObjectType}}}>(){}.getType()));
e.setErrorObjectType(new GenericType<{{{errorObjectType}}}>(){});
throw e;
}
{{/errorObjectType}}
{{^errorObjectType}}
Type localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
{{/errorObjectType}}
{{/returnType}}
}
{{/vendorExtensions.x-streaming}}{{^vendorExtensions.x-streaming}} ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException {
Expand All @@ -343,14 +349,20 @@ public class {{classname}} {
return localVarApiClient.execute(localVarCall);
{{/returnType}}
{{#returnType}}
{{#errorObjectType}}
try {
Type localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<{{{errorObjectType}}}{{^errorObjectType}}{{{returnType}}}{{/errorObjectType}}>(){}.getType()));
e.setErrorObjectType(new GenericType<{{{errorObjectType}}}{{^errorObjectType}}{{{returnType}}}{{/errorObjectType}}>(){});
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<{{{errorObjectType}}}>(){}.getType()));
e.setErrorObjectType(new GenericType<{{{errorObjectType}}}>(){});
throw e;
}
{{/errorObjectType}}
{{^errorObjectType}}
Type localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
{{/errorObjectType}}
{{/returnType}}
}
{{/vendorExtensions.x-streaming}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class ApiException extends{{#useRuntimeException}} RuntimeException {{/us
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
private {{{errorObjectType}}}{{^errorObjectType}}Object{{/errorObjectType}} errorObject = null;
{{#errorObjectType}}
private {{{errorObjectType}}} errorObject = null;
private GenericType errorObjectType = null;
{{/errorObjectType}}

/**
* <p>Constructor for ApiException.</p>
Expand Down Expand Up @@ -160,6 +162,7 @@ public class ApiException extends{{#useRuntimeException}} RuntimeException {{/us
public String getResponseBody() {
return responseBody;
}
{{#errorObjectType}}

/**
* Get the error object type.
Expand All @@ -184,7 +187,7 @@ public class ApiException extends{{#useRuntimeException}} RuntimeException {{/us
*
* @return Error object
*/
public {{{errorObjectType}}}{{^errorObjectType}}Object{{/errorObjectType}} getErrorObject() {
public {{{errorObjectType}}} getErrorObject() {
return errorObject;
}

Expand All @@ -193,7 +196,8 @@ public class ApiException extends{{#useRuntimeException}} RuntimeException {{/us
*
* @param errorObject Error object
*/
public void setErrorObject({{{errorObjectType}}}{{^errorObjectType}}Object{{/errorObjectType}} errorObject) {
public void setErrorObject({{{errorObjectType}}} errorObject) {
this.errorObject = errorObject;
}
{{/errorObjectType}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class ApiException extends Exception {
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
private Object errorObject = null;
private GenericType errorObjectType = null;

/**
* <p>Constructor for ApiException.</p>
Expand Down Expand Up @@ -155,40 +153,4 @@ public Map<String, List<String>> getResponseHeaders() {
public String getResponseBody() {
return responseBody;
}

/**
* Get the error object type.
*
* @return Error object type
*/
public GenericType getErrorObjectType() {
return errorObjectType;
}

/**
* Set the error object type.
*
* @param errorObjectType object type
*/
public void setErrorObjectType(GenericType errorObjectType) {
this.errorObjectType = errorObjectType;
}

/**
* Get the error object.
*
* @return Error object
*/
public Object getErrorObject() {
return errorObject;
}

/**
* Get the error object.
*
* @param errorObject Error object
*/
public void setErrorObject(Object errorObject) {
this.errorObject = errorObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,8 @@ public InputStream postPing(SomeObj someObj) throws ApiException {
*/
public InputStream postPingWithHttpInfo(SomeObj someObj) throws ApiException {
okhttp3.Call localVarCall = postPingValidateBeforeCall(someObj, null);
try {
Type localVarReturnType = new TypeToken<SomeObj>(){}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<SomeObj>(){}.getType()));
e.setErrorObjectType(new GenericType<SomeObj>(){});
throw e;
}
Type localVarReturnType = new TypeToken<SomeObj>(){}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class ApiException extends Exception {
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;
private Object errorObject = null;
private GenericType errorObjectType = null;

/**
* <p>Constructor for ApiException.</p>
Expand Down Expand Up @@ -155,40 +153,4 @@ public Map<String, List<String>> getResponseHeaders() {
public String getResponseBody() {
return responseBody;
}

/**
* Get the error object type.
*
* @return Error object type
*/
public GenericType getErrorObjectType() {
return errorObjectType;
}

/**
* Set the error object type.
*
* @param errorObjectType object type
*/
public void setErrorObjectType(GenericType errorObjectType) {
this.errorObjectType = errorObjectType;
}

/**
* Get the error object.
*
* @return Error object
*/
public Object getErrorObject() {
return errorObject;
}

/**
* Get the error object.
*
* @param errorObject Error object
*/
public void setErrorObject(Object errorObject) {
this.errorObject = errorObject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,8 @@ public Client call123testSpecialTags(Client body) throws ApiException {
*/
public ApiResponse<Client> call123testSpecialTagsWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = call123testSpecialTagsValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,8 @@ public Boolean fakeOuterBooleanSerialize(Boolean body) throws ApiException {
*/
public ApiResponse<Boolean> fakeOuterBooleanSerializeWithHttpInfo(Boolean body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterBooleanSerializeValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<Boolean>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Boolean>(){}.getType()));
e.setErrorObjectType(new GenericType<Boolean>(){});
throw e;
}
Type localVarReturnType = new TypeToken<Boolean>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down Expand Up @@ -454,14 +448,8 @@ public OuterComposite fakeOuterCompositeSerialize(OuterComposite body) throws Ap
*/
public ApiResponse<OuterComposite> fakeOuterCompositeSerializeWithHttpInfo(OuterComposite body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterCompositeSerializeValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<OuterComposite>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<OuterComposite>(){}.getType()));
e.setErrorObjectType(new GenericType<OuterComposite>(){});
throw e;
}
Type localVarReturnType = new TypeToken<OuterComposite>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down Expand Up @@ -589,14 +577,8 @@ public BigDecimal fakeOuterNumberSerialize(BigDecimal body) throws ApiException
*/
public ApiResponse<BigDecimal> fakeOuterNumberSerializeWithHttpInfo(BigDecimal body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterNumberSerializeValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<BigDecimal>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<BigDecimal>(){}.getType()));
e.setErrorObjectType(new GenericType<BigDecimal>(){});
throw e;
}
Type localVarReturnType = new TypeToken<BigDecimal>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down Expand Up @@ -724,14 +706,8 @@ public String fakeOuterStringSerialize(String body) throws ApiException {
*/
public ApiResponse<String> fakeOuterStringSerializeWithHttpInfo(String body) throws ApiException {
okhttp3.Call localVarCall = fakeOuterStringSerializeValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<String>(){}.getType()));
e.setErrorObjectType(new GenericType<String>(){});
throw e;
}
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down Expand Up @@ -1134,14 +1110,8 @@ public Client testClientModel(Client body) throws ApiException {
*/
public ApiResponse<Client> testClientModelWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = testClientModelValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,8 @@ public Client testClassname(Client body) throws ApiException {
*/
public ApiResponse<Client> testClassnameWithHttpInfo(Client body) throws ApiException {
okhttp3.Call localVarCall = testClassnameValidateBeforeCall(body, null);
try {
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
} catch (ApiException e) {
e.setErrorObject(localVarApiClient.getJSON().getGson().fromJson(e.getResponseBody(), new TypeToken<Client>(){}.getType()));
e.setErrorObjectType(new GenericType<Client>(){});
throw e;
}
Type localVarReturnType = new TypeToken<Client>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
Expand Down
Loading