Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set global header in swagger-ui.html , never invisible or not submit when try #2779

Open
farsunset-com opened this issue Nov 14, 2024 · 1 comment

Comments

@farsunset-com
Copy link

srpingboot 3.2.5
springdoc 2.6.0

like swagger2

private List<SecurityScheme> securitySchemes() {
    List<SecurityScheme> schemeList = new ArrayList<>();
    schemeList.add(new ApiKey(Common.MVC_HEADER_TOKEN, Common.MVC_HEADER_TOKEN, "header"));
    return schemeList;
}
@farsunset-com
Copy link
Author

farsunset-com commented Nov 14, 2024

The document is not very clear, this is work fine

@Bean
    public OpenAPI springDocOpenAPI() {
        OpenAPI api = new OpenAPI();

        api.components(new Components().addSecuritySchemes("x-token", new SecurityScheme()
                .type(SecurityScheme.Type.APIKEY)
                .in(SecurityScheme.In.HEADER)
                .name("x-token")
                .description("用户Token")));

        api.info(new Info()
                .title("Service APIs.")
                .description("系统业务接口服务")
                .version("3.0.0")
        );
        api.addSecurityItem(new SecurityRequirement().addList("x-token"));
        
        return api;

    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant