-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java][client] Fix feign classcastexception when getting headers (#16745
) * Avoid ClassCastException when getting headers (the header values are Collection<String> and not List<String>) Delete unused classes * Remove feign10x * Add unit test Refactor to avoid creating the headers map when ApiResponse is not used
- Loading branch information
1 parent
494ee48
commit 87f9d53
Showing
11 changed files
with
89 additions
and
107 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
38 changes: 0 additions & 38 deletions
38
.../java/feign-no-nullable/src/main/java/org/openapitools/client/JacksonResponseDecoder.java
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
31 changes: 0 additions & 31 deletions
31
...tore/java/feign-no-nullable/src/main/java/org/openapitools/client/model/HttpResponse.java
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
60 changes: 60 additions & 0 deletions
60
...ent/petstore/java/feign/src/test/java/org/openapitools/client/ApiResponseDecoderTest.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,60 @@ | ||
package org.openapitools.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.collect.ImmutableMap; | ||
import feign.Request; | ||
import feign.Request.HttpMethod; | ||
import feign.RequestTemplate; | ||
import feign.Response; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
import org.openapitools.client.model.ApiResponse; | ||
import org.openapitools.client.model.Cat; | ||
|
||
class ApiResponseDecoderTest { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
ApiResponseDecoder decoder = new ApiResponseDecoder(objectMapper); | ||
|
||
|
||
@Test | ||
void shouldDecodeApiResponseWithHeaders() throws IOException { | ||
|
||
final Cat cat = makeCat(); | ||
TypeReference<ApiResponse<Cat>> typeReference = new TypeReference<ApiResponse<Cat>>() { | ||
}; | ||
|
||
ApiResponse<Cat> response = (ApiResponse<Cat>) decoder.decode(Response.builder() | ||
.headers(ImmutableMap.of("Location", | ||
Collections.singletonList("https://example.com/cats/1"))) | ||
.body(objectMapper.writeValueAsBytes(cat)) | ||
.status(201) | ||
.request(buildRequest()) | ||
.build(), typeReference.getType()); | ||
|
||
assertEquals(cat.getColor(), response.getData().getColor()); | ||
assertEquals(cat.isDeclawed(), response.getData().isDeclawed()); | ||
|
||
Collection<String> locationValues = response.getHeaders().get("Location"); | ||
assertEquals(1, locationValues.size()); | ||
assertEquals("https://example.com/cats/1", locationValues.iterator().next()); | ||
} | ||
|
||
private Cat makeCat() { | ||
final Cat cat = new Cat(); | ||
cat.color("black"); | ||
cat.declawed(true); | ||
return cat; | ||
} | ||
|
||
private Request buildRequest() { | ||
return Request.create(HttpMethod.GET, "https://example.com/cats/1", Collections.emptyMap(), | ||
null, new RequestTemplate()); | ||
} | ||
} |