2017-09-05 26 views
0

我正在用swagger來記錄我的休息apis。Swagger不採用空值的方法

一個例子:

@RequestMapping(value = "/abc/api/fruit", produces = "application/json") 
@Controller 
@Api(value = "Fruit", description = "api for fruits", produces = "application/json") 
public class FruitResource { 

@RequestMapping(method = RequestMethod.GET, value = "") 
@ResponseBody 
@ApiOperation(httpMethod = "GET", value = "Resource to get fruits", produces = "application/json", notes = "get fruits", response=Fruit.class) 
public ResponseEntity<Fruit> getFruits() throws Exception { 
    return new ResponseEntity<Fruit>(someServiceCallToGetFruits(), HttpStatus.OK); 
} 
} 

如上所見,在RequestMappingvalue上述方法是空的( 「」)。

正因爲如此,這個班級和方法沒有被大肆宣揚。

但是,當我改變RequestMapping線上面的方法如下:

@RequestMapping(method = RequestMethod.GET, value = "/") 

它開始工作。

這是一個錯誤?我怎樣才能讓swagger與""路徑值一起工作。我不想把"/"放在所有這些方法之上。

+1

你試過不指定空值?像'@RequestMapping(method = RequestMethod.GET)'或'@GetMapping()'? –

+0

這裏是@ @ RequestMapping,是一個註釋?當它與value =「/」一起工作時,swagger上顯示的完整路徑是什麼? – nullpointer

+0

@AlekseiBudiak:工作..謝謝! – Nik

回答

3

如果您不想爲特定方法添加擴展API路徑,則不需要顯式指定空值。相反,下面的註釋可用於:

@RequestMapping(method = RequestMethod.GET) 

甚至

@GetMapping()