I answer this with the swagger2 configuration inside the spring boot application. Below is the configuration required for Swagger2.
Add gradle Configuration
Add gradle dependencies inside build.gradle file
dependencies { compile("io.springfox:springfox-swagger2:2.0.2") compile("io.springfox:springfox-swagger-ui:2.0.2") }
Swagger2 Lock Class
@Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket userApi() { return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()).build().pathMapping("/") .directModelSubstitute(LocalDate.class, String.class) .genericModelSubstitutes(ResponseEntity.class) .alternateTypeRules(newRule( typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)), typeResolver.resolve(WildcardType.class))) .useDefaultResponseMessages(false) .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message") .responseModel(new ModelRef("Error")).build())) .securitySchemes(newArrayList(apiKey())).securityContexts(newArrayList(securityContext())) .apiInfo(apiInfo()); } @Autowired private TypeResolver typeResolver; private ApiKey apiKey() { return new ApiKey("mykey", "api_key", "header"); } private SecurityContext securityContext() { return SecurityContext.builder().securityReferences(defaultAuth()) .forPaths(PathSelectors.regex("/anyPath.*")).build(); } List<SecurityReference> defaultAuth() { AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; authorizationScopes[0] = authorizationScope; return newArrayList(new SecurityReference("mykey", authorizationScopes)); } @Bean SecurityConfiguration security() { return new SecurityConfiguration("123456", "test-app-realm", "clientapp", "apiKey"); } @Bean UiConfiguration uiConfig() { return new UiConfiguration("validatorUrl"); } private ApiInfo apiInfo() { ApiInfo apiInfo = new ApiInfo("DSM API", "API for DSM", "1.0.0", "termsOfServiceUrl", " nijo@ndimensionz.com ", null, null); return apiInfo; } }
Add Swagger UI
Download Swagger UI from github. Copy the dist folder to the src / main / resources / static directory and rename dist to swagger
HomeController.class
@Api(basePath = "/", value = "/", description = "Home Controller") @Controller public class HomeController { @RequestMapping("/") public String home() { return "redirect:swagger-ui.html"; } }
Myapplication.class
@SpringBootApplication @ComponentScan(basePackageClasses = SwaggerConfig.class) public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
Configure the spring boot application with dependencies and run to see the API.
The URL will be http: // localhost: 8080 / v2 / swagger-ui.html you can also configure this as the answer above.