首页 > 解决方案 > @ApiOperation 中指定的标签不会覆盖@Api swagger ui 中指定的标签

问题描述

我已将类级别的标签指定为“用户”,并在此类下指定了一个 API,标签为“用户详细信息”。但是在 swagger ui 上,我可以看到这个 api 出现在两个标签下。如何仅在“用户详细信息”标签下而不是在“用户”标签下大摇大摆地显示此 API

@Api(tags = {"Users"}, description = "Manage Users")
@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    UserRepository userRepository;

    @Autowired
    AuditLogService auditLogService;

    Logger logger = LoggerFactory.getLogger(UserController.class);

    @ApiOperation(tags = {"User Details"})
    @GetMapping("/lastName/{lastName}")
    public List<UserGetResponse> findByLastName(@PathVariable String lastName) throws InterruptedException {
        logger.info("Received request to get users by last name, time: {}", LocalDateTime.now());
        List<UserGetResponse> userGetResponses = userService.getUsersByLastName(lastName);
        logger.info("Received response, Going to publish message to MQ, time: {}", LocalDateTime.now());
        auditLogService.publishMessage();
        return userGetResponses;
    }

标签: springswagger-ui

解决方案


我遇到了类似的问题。我正在使用springfox。如果您也在使用 springfox,也许这可能会有所帮助

https://github.com/springfox/springfox/issues/1257

简短的回答是这是意料之中的。原因是这些注解在 springfox 中的使用方式与 swagger-core 使用它的方式非常不同。例如,我们不支持像 @SwaggerDefinition 这样的结构

在这种情况下,我的建议是实现您自己的操作插件,根据您的需要覆盖这些值。


推荐阅读