df7159059e8433b930bac710ddf6b8d3c353e9b1
[SpringWebServicesForFun/.git] /
1 package de.spring.webservices.doc;
2
3 import static com.google.common.collect.Lists.newArrayList;
4
5 import org.springframework.context.annotation.Bean;
6 import org.springframework.context.annotation.ComponentScan;
7 import org.springframework.context.annotation.Configuration;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RequestMethod;
10 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
11
12 import springfox.documentation.builders.ApiInfoBuilder;
13 import springfox.documentation.builders.PathSelectors;
14 import springfox.documentation.builders.RequestHandlerSelectors;
15 import springfox.documentation.builders.ResponseMessageBuilder;
16 import springfox.documentation.service.ApiInfo;
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.swagger1.annotations.EnableSwagger;
21
22 @Configuration
23 @EnableWebMvc
24 @EnableSwagger
25 @ComponentScan("de.spring.webservices.rest.controller")
26 public class Swagger2Configuration {
27         
28         @Bean
29         public Docket documentation() {
30                 return new Docket(DocumentationType.SWAGGER_12)
31                                 .select()
32                                         .apis(RequestHandlerSelectors.withMethodAnnotation(RequestMapping.class))
33                                         .paths(PathSelectors.any())
34                                         .build()
35                                         .globalResponseMessage(RequestMethod.GET,
36                                                         newArrayList(new ResponseMessageBuilder()
37                                                                         .code(500).message("Global server custom error message").build()))
38                         .pathMapping("/")
39                         .useDefaultResponseMessages(false)
40                         .apiInfo(metadata())
41                         .enable(true);
42         }
43
44         @Bean
45         UiConfiguration uiConfig() {
46                 return UiConfiguration.DEFAULT;
47         }
48         
49         private static ApiInfo metadata() {
50                 return new ApiInfoBuilder()
51                                 .title("gumartinm REST API")
52                                 .description("Gustavo Martin Morcuende")
53                                 .version("1.0-SNAPSHOT")
54                         .contact("gumartinm.name")
55                         .build();
56         }
57
58 }