我正在使用springdoc-openapi-ui
. 我已经配置了名为Authorization
. 当我执行 APIAuthorization
时,请求的 CURL 中没有显示。我的其他参数显示在 CURL 中,除了Authorization
.
以前,我使用的是springfox-swagger-ui
,当时它显示在 CURL 部分。
我搜索了相同的内容并在https://swagger.io/docs/specification/describing-parameters/#header-parameters上找到了注释
Note: Header parameters named Accept, Content-Type and Authorization are not allowed.
但我要求Authorization
仅用作标题。我们有什么办法可以做到这一点吗?
我SwaggerConfiguration
的添加在下面。
@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());
}
}