我想“手动”声明一种字段是swagger中的条目列表。
假设我完全习惯了
public class MyCustomList implements List<MyValue> {
....
}
现在我有一个模型类
@Data
public class MyModel {
public MyCustomList problematicField;
}
我想让Swagger明白MyCustomList
是MyValue
的列表(数组)。
在@ApiOperation
我设置了
@ApiOperation(value = "..", response = MyValue.class, responseContainer = "List")
答案 0 :(得分:0)
我相信您可以通过自定义模型转换器实现此目的。见这里:
https://github.com/swagger-api/swagger-core/wiki/overriding-models
有关手动转换类的指南,但简而言之,它看起来像这样:
import com.wordnik.swagger.converter.*;
String jsonString = "{" +
" \"id\": \"Date\"," +
" \"properties\": {" +
" \"value\": {" +
" \"required\": true," +
" \"description\": \"Date in ISO-8601 format\"," +
" \"notes\": \"Add any notes you like here\"," +
" \"type\": \"string\"," +
" \"format\": \"date-time\"" +
" }" +
" }" +
"}";
OverrideConverter converter = new OverrideConverter();
converter.add("java.util.Date", jsonString);
ModelConverters.addConverter(converter, true);