Monday, January 16, 2017

Springfox swagger UI upgrade

Few days ago I did an upgrade of springfox/swagger2 2.5.0 -> 2.6.1.
And it appeared, that authorisation API_KEY input field doesn't present on UI any more.
After a research it appeared, that springfox-swagger2 2.6.1 now completely support all original Swagger UI authentication types [basic, oauth2, api token]
All you need to do is to configure SecurityScheme for your Swagger Configuration like this:

 SecurityScheme securityScheme = new ApiKey(TOKEN_HEADER, "", TOKEN_TRANSPORT_HEADER);  
     return new Docket(DocumentationType.SWAGGER_2)  
         .select()  
         .apis(RequestHandlerSelectors.any())  
         .paths(PathSelectors.any())  
         .build()  
         .apiInfo(getApiInfo())  
         .securitySchemes(Lists.newArrayList(securityScheme));