Added auth to swagger-ui

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-11-09 17:08:51 +01:00
parent 7c7045c0e1
commit 029300815e
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -1,12 +1,18 @@
package com.plannaplan; package com.plannaplan;
import java.util.Collections;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.service.Parameter;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
@ -18,9 +24,15 @@ public class Swagger2Config extends WebMvcConfigurationSupport {
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
Parameter authHeader = new ParameterBuilder()
.parameterType("header")
.name("Authorization")
.modelRef(new ModelRef("string"))
.build();
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any()) .apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any())
.build(); .build()
.globalOperationParameters(Collections.singletonList(authHeader));
} }
@Override @Override