【问题标题】:Springfox: @ResponseHeader in @ApiResponse does not render in Swagger UISpringfox:@ApiResponse 中的 @ResponseHeader 不会在 Swagger UI 中呈现
【发布时间】:2018-09-06 22:20:26
【问题描述】:

我在代码中有Springfox注解如下:

    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "Options for the endpoint", responseHeaders = {@ResponseHeader(name = "Allow", description = "Verbs allowed")})})

但是,标头未在 Swagger UI 中的响应下方呈现。

如果我通过 Docket 添加全局响应(针对内部服务器错误),它的标头呈现得很好。

这是配置错误还是这里有什么问题?

【问题讨论】:

    标签: java spring swagger springfox


    【解决方案1】:

    我的问题是注释参数“response”没有设置为String.class。它默认为 Void.class 并且不使用它进行渲染。

    更正的代码是:

    @ApiResponse(code = 200, message = "Options for the endpoint", responseHeaders = {@ResponseHeader(name = "Allow", description = "Verbs allowed", response = String.class)})})
    

    【讨论】:

    • 感谢您的挖掘。这似乎不是一个非常明智的默认设置...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 2020-05-12
    相关资源
    最近更新 更多