2014-11-04 51 views
1

我想「手動」聲明一種類型的字段,作爲swagger中的條目列表。如何聲明作爲Swagger中的條目列表的類型

比方說,我有完全的自定義

public class MyCustomList implements List<MyValue> { 
.... 
} 

現在我有一個模型類

@Data 
public class MyModel { 
    public MyCustomList problematicField; 
} 

我想打揚鞭明白MyCustomListMyValue列表(陣列)。

@ApiOperation我設置

@ApiOperation(value = "..", response = MyValue.class, responseContainer = "List") 

回答

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); 
+0

啊,但是這種類型不具有屬性。這是一個東西的列表。 – 2014-11-06 10:25:22