Skip to content

Instantly share code, notes, and snippets.

@bayboraoren
Forked from RICH0423/SwaggerConfig.java
Created February 15, 2018 09:09
Show Gist options
  • Select an option

  • Save bayboraoren/d356343348637acd98749c1bfa1e7187 to your computer and use it in GitHub Desktop.

Select an option

Save bayboraoren/d356343348637acd98749c1bfa1e7187 to your computer and use it in GitHub Desktop.
Pass JWT token in swagger with Spring Boot and springfox
package com.rich.api.config;
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
*
* @author rich
*
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.delta.ssir.dbee.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.securitySchemes(Arrays.asList(apiKey()));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("REST API")
.description("The REST API for demo swagger.").termsOfServiceUrl("")
.contact(new Contact("RICH LEE", "", "rich.lee@gmail.com"))
.license("Apache License Version 2.0")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
.version("0.0.1")
.build();
}
private ApiKey apiKey() {
return new ApiKey("authkey", "Authorization", "header");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment