From 029300815ecdaebc467d130d9d0fb330c2799eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Mon, 9 Nov 2020 17:08:51 +0100 Subject: [PATCH] Added auth to swagger-ui MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .../main/java/com/plannaplan/Swagger2Config.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/restservice/src/main/java/com/plannaplan/Swagger2Config.java b/restservice/src/main/java/com/plannaplan/Swagger2Config.java index b1bd6d6..755928d 100755 --- a/restservice/src/main/java/com/plannaplan/Swagger2Config.java +++ b/restservice/src/main/java/com/plannaplan/Swagger2Config.java @@ -1,12 +1,18 @@ package com.plannaplan; +import java.util.Collections; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import springfox.documentation.service.Parameter; import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; @@ -18,9 +24,15 @@ public class Swagger2Config extends WebMvcConfigurationSupport { @Bean 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() .apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any()) - .build(); + .build() + .globalOperationParameters(Collections.singletonList(authHeader)); } @Override