2016-09-02 88 views
4

的请求参数提供样品值我有一个弹簧引导RestController休息方法的方法签名,看起来像这样:在扬鞭

@RequestMapping(
     value = "/path", 
     method = RequestMethod.POST, 
     consumes = MediaType.APPLICATION_JSON_VALUE, 
     produces = MediaType.APPLICATION_JSON_VALUE 
) 
@ApiImplicitParams({ 
     @ApiImplicitParam(
       name = "message", 
       value = "Message that is sent to the method", 
       required = true, 
       dataType = "string", 
       paramType = "body" 
     ) 
}) 
public @ResponseBody String receiveMessage(@RequestBody String message) { 
    // ... 

    return "{\"success\": true}"; 
} 

我想,以提供一个“样本”的价值message参数是一个JSON字符串(例如{"key" : "value"})。有谁知道我可以用Swagger注释来做到这一点吗?我试过

@ApiImplicitParams({ 
     @ApiImplicitParam(
       // ... 
       example = "...JSON value..." 
     ) 
}) 

但它没有工作。我想要的是文档中的“样本值”,读者可以点击使文档中的参数值字段填充给定的样本值。这可能吗?

这里是它如何可能看起来像一个截图:

enter image description here

只是不要阻止“无用”的答案:我不能参数的类型从String更改为某个类的类型,由于我的业务逻辑。

回答

3

不幸的是,您无法提供原子参数(String,Number,...)的示例或示例值。

只能提供一个例子,如果该参数是一个模式中的对象,你只需要一个example属性添加到属性描述:

properties: 
    firstName: 
    description: first name 
    type: string 
    example: John 

作为最后的手段,你可以添加一个例子值在参数描述中(valueApiImplicitParam注释中)。

@ApiImplicitParam(
      name = "message", 
      value = "Message that is sent to the method. Example: value", 
      required = true, 
      dataType = "string", 
      paramType = "body" 
    )