CURL springdoc-openapi-ui 中未显示授权标头 [英] Authorization Header not getting displayed in CURL springdoc-openapi-ui

查看:39
本文介绍了CURL springdoc-openapi-ui 中未显示授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 springdoc-openapi-ui.我已经配置了名为 Authorization 的全局标头.当我执行 API Authorization 没有显示在请求的 CURL 中.我的其他参数显示在 CURL 中,除了 Authorization.

以前,我使用的是 springfox-swagger-ui,那一次它显示在 CURL 部分.

我搜索了相同的内容并在

然后它将显示在 CURL 部分,如下所示.

cod 在 glabal 位置的 swagger 上启用授权按钮

@Configuration公共类 SwaggerConfiguration {@豆公共 OpenAPI customOpenAPI() {返回新的 OpenAPI().info(new信息().title("title").version("version").description("description")).addSecurityItem(new SecurityRequirement().addList("my security")).components(new Components().addSecuritySchemes("我的安全",new SecurityScheme().name("我的security").type(SecurityScheme.Type.HTTP).scheme("bearer")));}}

I am using the springdoc-openapi-ui. I have configured the global headers named Authorization. When I execute the API Authorization is not showing in the CURL of the requests. My other parameters are showing in the CURL except Authorization.

Previously, I was using the springfox-swagger-ui and that time it was showing in CURL section.

I have searched for the same and found Note on https://swagger.io/docs/specification/describing-parameters/#header-parameters Note: Header parameters named Accept, Content-Type and Authorization are not allowed.

But my requirement to use Authorization as header only. Is there any away we can achieve this?

My SwaggerConfiguration is added below.

@Configuration
public class SwaggerConfiguration {

    @Value("${title:title}")
    private String title;
    @Value("${description:description.}")
    private String description;
    @Value("${version:0.0.1}")
    private String version;

    @Value("${schemeId}")
    String schemeIdentifier;

    @Bean
    public OperationCustomizer customGlobalHeaders() {

        return (Operation operation, HandlerMethod handlerMethod) -> {

            Parameter authorization = new Parameter().in(ParameterIn.HEADER.toString()).name("Authorization")
                    .description("Authorization details JWT token")
                    .schema(new StringSchema()).required(true);

            Parameter applicationId = new Parameter().in(ParameterIn.HEADER.toString()).schema(new StringSchema())
                    .name("Application-Id").description("Originating application or client using the service")
                    .required(false);

            operation.addParametersItem(authorization);
            operation.addParametersItem(applicationId);

            return operation;
        };
    }

    @Bean
    public GroupedOpenApi adminApi() {      

        String[] packagesToscan = { "abc.controller" };

        return GroupedOpenApi.builder().setGroup("Client").packagesToScan(packagesToscan).build();
    }

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI().info(new Info().title(title).version(version).description(description))
                .components(new Components());
    }
}

解决方案

I have searched for an answer on the same.
We can not set Authorization as a header with springdoc open api. if we want to use then we need to enable the authorization button on swagger ui.

then it will shows in CURL section as shown below.

cod to enable authorization button on swagger in glabal location

@Configuration
public class SwaggerConfiguration {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI().info(new 
             Info().title("title").version("version").description("description"))
                .addSecurityItem(new SecurityRequirement().addList("my security"))
                .components(new Components().addSecuritySchemes("my security",
                        new SecurityScheme().name("my 
                 security").type(SecurityScheme.Type.HTTP).scheme("bearer")));
    }
}

这篇关于CURL springdoc-openapi-ui 中未显示授权标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆