gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 08:40:18 26 4
gpt4 key购买 nike

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

不幸的是,在我使用 @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

关于java - 当 Operation 未使用 @ApiOperation 注释时,Swagger 忽略 JAX-RS @Produces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com