当 Operation 未使用 @ApiOperation 注释时,Swagger 忽略 JAX-RS @Produces

Swagger ignoring JAX-RS @Produces when Operation is not annotated with @ApiOperation

我目前正在将 Swagger(1.5.7 版中的 swagger-jaxrs 工件)集成到我们现有的 JAX-RS REST 应用程序中。添加 Swagger 后,我将 @Api 注释添加到我们的界面 class 并且已经得到了一份看起来不错的文档。

不幸的是,在我使用 @ApiOperation:

注释这些方法之前,Swagger 不支持我的 API 方法上的 @Produces 注释

未将 text/plain 列为返回的媒体类型:

@GET
@Path("/overallStatus")
@Produces(MediaType.TEXT_PLAIN)
public String getOverallStatus() {
}

是否列出:

@GET
@Path("/overallStatus")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Get the overall system status")
public String getOverallStatus() {
}

有没有办法在不向所有媒体类型添加@ApiOperation 的情况下在 Swagger 输出中获得媒体类型?由于所需信息已经存在,我不明白我为什么需要它。

您必须将 @ApiOperation 添加到您的 JAX-RS 端点,因为根据 Swagger Wiki 页面,没有 @ApiOperation 注释的方法将被忽略:

Only methods that are annotated with @ApiOperation will be scanned and added the Swagger definition.

您可以在此处找到更多信息:https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#apioperation