【问题标题】:Default value for accept header using springdoc-openapi使用 springdoc-openapi 接受标头的默认值
【发布时间】:2020-04-20 23:11:39
【问题描述】:

我正在使用 springdoc-openapi 库来自动生成和渲染 swagger-ui。我需要为接受标头添加默认值。如何做到这一点?

springfox 允许使用 ParameterBuilder 的 defaultValue 函数来做到这一点。附上截图。我想在不使用 springfox 的情况下达到同样的效果。

【问题讨论】:

    标签: swagger springdoc


    【解决方案1】:

    如果您需要在所有操作的 Header 中添加全局参数,您可以使用 OperationCustomizer :

    @Bean
    public OperationCustomizer addCustomGlobalHeader() {
        return (Operation operation, HandlerMethod handlerMethod) -> {
            Parameter headerParameter = new Parameter().in(ParameterIn.HEADER.toString()).required(true).
                    schema(new StringSchema().
                            _default("application/json;api-verision=1.0")).name("Accept");
            operation.addParametersItem(headerParameter);
            return operation;
        };
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-08
      • 2020-10-02
      • 2020-09-24
      • 2015-11-14
      • 2022-10-18
      • 2022-11-03
      • 2022-11-10
      • 2020-09-17
      • 1970-01-01
      相关资源
      最近更新 更多