c4ea5bf557bfc6158e9cc7cbd2d675a5394adce4
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.configuration;
2
3 import static com.google.common.collect.Lists.newArrayList;
4 import static springfox.documentation.builders.RequestHandlerSelectors.basePackage;
5 import static springfox.documentation.builders.RequestHandlerSelectors.withMethodAnnotation;
6
7 import org.springframework.context.annotation.Bean;
8 import org.springframework.context.annotation.Configuration;
9 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.bind.annotation.RequestMethod;
11
12 import springfox.documentation.builders.ApiInfoBuilder;
13 import springfox.documentation.builders.PathSelectors;
14 import springfox.documentation.builders.ResponseMessageBuilder;
15 import springfox.documentation.service.ApiInfo;
16 import springfox.documentation.service.Contact;
17 import springfox.documentation.spi.DocumentationType;
18 import springfox.documentation.spring.web.plugins.Docket;
19 import springfox.documentation.swagger.web.UiConfiguration;
20 import springfox.documentation.swagger2.annotations.EnableSwagger2;
21
22 /**
23  * Go to URL: http://localhost:8080/swagger-ui.html#/
24  *
25  */
26 @Configuration
27 @EnableSwagger2
28 public class Swagger2Configuration {
29         
30         @Bean
31         public Docket documentation() {
32                 return new Docket(DocumentationType.SWAGGER_2)
33                                 .select()
34                                         .apis(withMethodAnnotation(RequestMapping.class))
35                                         .apis(basePackage("de.spring.webservices.rest.controller"))
36                                         .paths(PathSelectors.any())
37                                         .build()
38                                         .globalResponseMessage(RequestMethod.GET,
39                                                         newArrayList(new ResponseMessageBuilder()
40                                                                         .code(500).message("Global server custom error message").build()))
41                         .useDefaultResponseMessages(false)
42                         .apiInfo(metadata())
43                         .enable(true);
44         }
45
46         @Bean
47         UiConfiguration uiConfig() {
48                 return new UiConfiguration(null);
49         }
50         
51         private static ApiInfo metadata() {
52                 return new ApiInfoBuilder()
53                                 .title("gumartinm REST API")
54                                 .description("Gustavo Martin Morcuende")
55                                 .version("1.0-SNAPSHOT")
56                         .contact(doContact())
57                         .build();
58         }
59
60         private static Contact doContact() {
61                 return new Contact("Gustavo Martin", "https://gumartinm.name", "");
62         }
63 }