-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java][Feign] Add http status to feign result (#10583)
* Add .circleci/config.yml * Add Http status to the feign response wrapper * Add Http status to the feign response wrapper * Add Http status to the feign response wrapper Fix typo * Add Http status to the feign response wrapper Fix typo * Rename HttpResponse to ApiResponse
- Loading branch information
1 parent
357f186
commit ff286aa
Showing
34 changed files
with
393 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
modules/openapi-generator/src/main/resources/Java/libraries/feign/model/ApiResponse.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package {{modelPackage}}; | ||
|
||
import java.util.Map; | ||
import java.util.List; | ||
|
||
public class ApiResponse<T>{ | ||
final private int statusCode; | ||
final private Map<String, List<String>> headers; | ||
final private T data; | ||
/** | ||
* @param statusCode The status code of HTTP response | ||
* @param headers The headers of HTTP response | ||
*/ | ||
public ApiResponse(int statusCode, Map<String, List<String>> headers) { | ||
this(statusCode, headers, null); | ||
} | ||
|
||
/** | ||
* @param statusCode The status code of HTTP response | ||
* @param headers The headers of HTTP response | ||
* @param data The object deserialized from response bod | ||
*/ | ||
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) { | ||
this.statusCode = statusCode; | ||
this.headers = headers; | ||
this.data = data; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
public Map<String, List<String>> getHeaders() { | ||
return headers; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
} |
24 changes: 0 additions & 24 deletions
24
...les/openapi-generator/src/main/resources/Java/libraries/feign/model/HttpResponse.mustache
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...tore/java/feign-no-nullable/src/main/java/org/openapitools/client/ApiResponseDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.openapitools.client; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import feign.Response; | ||
import feign.Types; | ||
import feign.jackson.JacksonDecoder; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.openapitools.client.model.ApiResponse; | ||
|
||
public class ApiResponseDecoder extends JacksonDecoder { | ||
|
||
public ApiResponseDecoder(ObjectMapper mapper) { | ||
super(mapper); | ||
} | ||
|
||
@Override | ||
public Object decode(Response response, Type type) throws IOException { | ||
Map<String, Collection<String>> responseHeaders = Collections.unmodifiableMap(response.headers()); | ||
//Detects if the type is an instance of the parameterized class ApiResponse | ||
Type responseBodyType; | ||
if (Types.getRawType(type).isAssignableFrom(ApiResponse.class)) { | ||
//The ApiResponse class has a single type parameter, the Dto class itself | ||
responseBodyType = ((ParameterizedType) type).getActualTypeArguments()[0]; | ||
Object body = super.decode(response, responseBodyType); | ||
return new ApiResponse(response.status(), responseHeaders, body); | ||
} else { | ||
//The response is not encapsulated in the ApiResponse, decode the Dto as normal | ||
return super.decode(response, type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.