I try to use springfox to generate API documentation, but when I set the Http response body to a generic type, a problem occurs and it cannot be parsed correctly
I am using the following version of springfox
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
I wrote a class with generics and tried to return it via http response, with the code like this
// wrapper class
@Data
public class TestResp<T> {
private T data;
}
// data
@Data
public class TestData {
private String testMsg;
public TestData(String testMsg) { this.testMsg = testMsg; }
}
// controller
@RestController
public class TestController {
@GetMapping("test")
@ApiOperation("test")
private TestResp<TestData> testResp() {
return new TestResp<>(new TestData("test"));
}
}
So far it looks fine, but! When I tried to open swagger-ui, a strange scene occurred:
{
"schemas": {
"TestData": {
"title": "TestData",
"type": "object",
"properties": {
"testMsg": {
"type": "string"
}
}
},
"TestResp«TestData»": {
"title": "TestResp«TestData»",
"type": "object",
"properties": {
"data": {
"type": "object" // Why is the type of data not TestData but object?
}
}
}
}
}
I think it should be able to display generic types normally. I remember it was possible before, but I don’t know why it’s like this now.
retblank zero is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.