【问题标题】:Swagger not picking methods with empty valueSwagger 不选择具有空值的方法
【发布时间】:2017-09-05 03:50:53
【问题描述】:

我正在使用 swagger 来记录我的其余 api。

一个例子:

@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);
}
}

如上所见,上述方法RequestMapping中的value为空(“”)。

正因为如此,这个类和方法没有被招摇。

但是当我将上述方法的 RequestMapping 行更改为如下:

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

它开始工作。

这是一个错误吗?我怎样才能使大摇大摆地使用"" 路径值。我不想把"/" 放在所有这些方法之上。

【问题讨论】:

  • 您是否尝试过不指定空值?喜欢@RequestMapping(method = RequestMethod.GET)@GetMapping()
  • 这里的@RequestMapping是spring注解吗?另外,当它与 value="/" 一起使用时,swagger 上显示的完整路径是什么?
  • @AlekseiBudiak:那行得通..谢谢!!
  • @Nik 很高兴它有帮助!

标签: java spring rest spring-mvc swagger


【解决方案1】:

如果您不想为特定方法添加扩展 API 路径,则无需显式指定空值。相反,可以使用以下注释:

@RequestMapping(method = RequestMethod.GET)

甚至

@GetMapping()

【讨论】:

    猜你喜欢
    • 2023-01-10
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多