![](/img/trans.png)
[英]Swagger + Spring Boot, how to set the example value to be passed in the API based on Spring Boot Validation
[英]Swagger on Spring boot - How do I set example value for a POST method that requires a parameter?
我有一個 POST 方法/predict
public ResponseEntity predict(@RequestBody Map<String, Object> inputs) {...}
現在在 Swagger UI 上,我只在Example Value
下看到空地圖
我有一個名為RequestInput
的類,它具有輸入的結構。 但是我做不到
public ResponseEntity predict(@RequestBody RequestInput requestInput) {...}
因為Map<String, Object> inputs
是 POST 請求的預期輸入。 我試過
public ResponseEntity predict(@RequestBody Map<String, Object> inputs, @RequestBody RequestInput requestInput) {...}
它將在Example Value
顯示RequestInput
但預測將失敗,因為它檢測到RequestInput
作為參數並且它會拋出nullpointerexception
您可以使用添加@ApiParam
注釋之類的
public ResponseEntity predict(@ApiParam(defaultValue = "{\"key\":\"value\"}") @RequestBody Map<String, Object> inputs) {...}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.