Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit a75a096

Browse files
authored
fixes missing generics in response entity (#159)
1 parent 9a7fa04 commit a75a096

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/payload/AbstractJacksonFieldSnippet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ protected Collection<FieldDescriptor> createFieldDescriptors(Operation operation
8787
}
8888

8989
protected Type firstGenericType(MethodParameter param) {
90-
return ((ParameterizedType) param.getGenericParameterType()).getActualTypeArguments()[0];
90+
Type type = param.getGenericParameterType();
91+
if (type != null && type instanceof ParameterizedType) {
92+
return ((ParameterizedType) type).getActualTypeArguments()[0];
93+
} else {
94+
return Object.class;
95+
}
9196
}
9297

9398
protected abstract Type getType(HandlerMethod method);

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/payload/JacksonResponseFieldSnippetTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ public void responseEntityResponse() throws Exception {
177177
.build());
178178
}
179179

180+
@Test
181+
public void responseEntityResponseWithoutGenerics() throws Exception {
182+
HandlerMethod handlerMethod = createHandlerMethod("responseEntityItem2");
183+
184+
this.snippets.expect(RESPONSE_FIELDS).withContents(equalTo("No response body."));
185+
186+
new JacksonResponseFieldSnippet().document(operationBuilder
187+
.attribute(HandlerMethod.class.getName(), handlerMethod)
188+
.attribute(ObjectMapper.class.getName(), mapper)
189+
.attribute(JavadocReader.class.getName(), javadocReader)
190+
.attribute(ConstraintReader.class.getName(), constraintReader)
191+
.build());
192+
}
193+
180194
@Test
181195
public void exactResponseType() throws Exception {
182196
HandlerMethod handlerMethod = createHandlerMethod("processItem");
@@ -299,6 +313,10 @@ public ResponseEntity<Item> responseEntityItem() {
299313
return ResponseEntity.ok(new Item("test"));
300314
}
301315

316+
public ResponseEntity responseEntityItem2() {
317+
return ResponseEntity.ok(new Item("test"));
318+
}
319+
302320
public String processItem() {
303321
return "";
304322
}

0 commit comments

Comments
 (0)