|
1 | 1 | package io.github.atkawa7.httpsnippet.demo.config; |
2 | 2 |
|
3 | | -import io.github.atkawa7.httpsnippet.demo.domain.EntityMarker; |
4 | | -import io.github.atkawa7.httpsnippet.demo.processors.SpeakerProcessor; |
5 | | -import io.github.atkawa7.httpsnippet.demo.processors.SpeakerProcessorImpl; |
6 | | -import io.github.atkawa7.httpsnippet.demo.repository.RepositoryMarker; |
7 | | -import io.github.atkawa7.httpsnippet.demo.repository.SpeakerRepository; |
8 | | -import io.github.atkawa7.httpsnippet.demo.resources.SpeakerResource; |
9 | | -import io.github.atkawa7.httpsnippet.demo.service.SpeakerService; |
10 | | -import io.github.atkawa7.httpsnippet.demo.service.SpeakerServiceImpl; |
11 | | -import io.github.atkawa7.httpsnippet.demo.swagger.extensions.ExternalDocsVendorExtension; |
12 | | -import io.github.atkawa7.httpsnippet.demo.swagger.extensions.LogoVendorExtension; |
13 | | -import io.github.atkawa7.httpsnippet.demo.swagger.plugins.CodeSampleOperationBuilderPlugin; |
14 | | -import io.github.atkawa7.httpsnippet.http.MediaType; |
| 3 | +import java.util.Collections; |
| 4 | +import java.util.HashSet; |
| 5 | +import java.util.List; |
| 6 | +import java.util.Set; |
| 7 | + |
15 | 8 | import org.springframework.boot.autoconfigure.domain.EntityScan; |
16 | 9 | import org.springframework.context.annotation.Bean; |
17 | 10 | import org.springframework.context.annotation.Configuration; |
18 | 11 | import org.springframework.core.env.Environment; |
19 | 12 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
| 13 | + |
20 | 14 | import springfox.documentation.builders.ApiInfoBuilder; |
21 | 15 | import springfox.documentation.builders.PathSelectors; |
22 | 16 | import springfox.documentation.builders.RequestHandlerSelectors; |
|
28 | 22 | import springfox.documentation.spring.web.plugins.Docket; |
29 | 23 | import springfox.documentation.swagger2.annotations.EnableSwagger2; |
30 | 24 |
|
31 | | -import java.util.Collections; |
32 | | -import java.util.HashSet; |
33 | | -import java.util.List; |
34 | | -import java.util.Set; |
| 25 | +import io.github.atkawa7.httpsnippet.demo.domain.EntityMarker; |
| 26 | +import io.github.atkawa7.httpsnippet.demo.processors.SpeakerProcessor; |
| 27 | +import io.github.atkawa7.httpsnippet.demo.processors.SpeakerProcessorImpl; |
| 28 | +import io.github.atkawa7.httpsnippet.demo.repository.RepositoryMarker; |
| 29 | +import io.github.atkawa7.httpsnippet.demo.repository.SpeakerRepository; |
| 30 | +import io.github.atkawa7.httpsnippet.demo.resources.SpeakerResource; |
| 31 | +import io.github.atkawa7.httpsnippet.demo.service.SpeakerService; |
| 32 | +import io.github.atkawa7.httpsnippet.demo.service.SpeakerServiceImpl; |
| 33 | +import io.github.atkawa7.httpsnippet.demo.swagger.extensions.ExternalDocsVendorExtension; |
| 34 | +import io.github.atkawa7.httpsnippet.demo.swagger.extensions.LogoVendorExtension; |
| 35 | +import io.github.atkawa7.httpsnippet.demo.swagger.plugins.CodeSampleOperationBuilderPlugin; |
| 36 | +import io.github.atkawa7.httpsnippet.http.MediaType; |
35 | 37 |
|
36 | 38 | @Configuration |
37 | 39 | @EntityScan(basePackageClasses = EntityMarker.class) |
38 | 40 | @EnableJpaRepositories(basePackageClasses = RepositoryMarker.class) |
39 | 41 | @EnableSwagger2 |
40 | 42 | public class DemoConfig { |
41 | | - @Bean |
42 | | - public DemoProperties demoProperties(Environment environment) { |
43 | | - return new DemoProperties(environment); |
44 | | - } |
| 43 | + @Bean |
| 44 | + public DemoProperties demoProperties(Environment environment) { |
| 45 | + return new DemoProperties(environment); |
| 46 | + } |
45 | 47 |
|
46 | | -@Bean |
47 | | -public SpeakerService speakerService(SpeakerRepository speakerRepository) { |
48 | | - return new SpeakerServiceImpl(speakerRepository); |
49 | | -} |
| 48 | + @Bean |
| 49 | + public SpeakerService speakerService(SpeakerRepository speakerRepository) { |
| 50 | + return new SpeakerServiceImpl(speakerRepository); |
| 51 | + } |
50 | 52 |
|
51 | | -@Bean |
52 | | -public SpeakerProcessor speakerProcessor(SpeakerService speakerService) { |
53 | | - return new SpeakerProcessorImpl(speakerService); |
54 | | -} |
| 53 | + @Bean |
| 54 | + public SpeakerProcessor speakerProcessor(SpeakerService speakerService) { |
| 55 | + return new SpeakerProcessorImpl(speakerService); |
| 56 | + } |
55 | 57 |
|
56 | | -@Bean |
57 | | -public CodeSampleOperationBuilderPlugin codeSampleProcessor(DemoProperties demoProperties) { |
58 | | - return new CodeSampleOperationBuilderPlugin(demoProperties); |
59 | | -} |
| 58 | + @Bean |
| 59 | + public CodeSampleOperationBuilderPlugin codeSampleProcessor(DemoProperties demoProperties) { |
| 60 | + return new CodeSampleOperationBuilderPlugin(demoProperties); |
| 61 | + } |
60 | 62 |
|
61 | | -@Bean |
62 | | -public Docket docket(DemoProperties demoProperties) { |
| 63 | + @Bean |
| 64 | + public Docket docket(DemoProperties demoProperties) { |
63 | 65 |
|
64 | | - Set<String> protocols = new HashSet<>(Collections.singleton("http")); |
| 66 | + Set<String> protocols = new HashSet<>(Collections.singleton("http")); |
65 | 67 |
|
66 | | - List<VendorExtension> apiInfoVendorExtensions = |
67 | | - Collections.singletonList( |
68 | | - new LogoVendorExtension(demoProperties).getObjectVendorExtension()); |
69 | | - List<VendorExtension> docketVendorExtensions = |
70 | | - Collections.singletonList( |
71 | | - new ExternalDocsVendorExtension(demoProperties).getObjectVendorExtension()); |
72 | | - ApiInfo apiInfo = |
73 | | - new ApiInfoBuilder() |
74 | | - .title(demoProperties.getApplicationName()) |
75 | | - .description(demoProperties.getApplicationDescription()) |
76 | | - .contact( |
77 | | - new Contact( |
78 | | - demoProperties.getApplicationName(), |
79 | | - demoProperties.getApplicationDomain(), |
80 | | - demoProperties.getApplicationSupport())) |
81 | | - .license(demoProperties.getApplicationLicenseName()) |
82 | | - .licenseUrl(demoProperties.getApplicationLicenseUrl()) |
83 | | - .version(demoProperties.getApplicationVersion()) |
84 | | - .termsOfServiceUrl(demoProperties.getApplicationLicenseUrl()) |
85 | | - .extensions(apiInfoVendorExtensions) |
86 | | - .build(); |
| 68 | + List<VendorExtension> apiInfoVendorExtensions = |
| 69 | + Collections.singletonList( |
| 70 | + new LogoVendorExtension(demoProperties).getObjectVendorExtension()); |
| 71 | + List<VendorExtension> docketVendorExtensions = |
| 72 | + Collections.singletonList( |
| 73 | + new ExternalDocsVendorExtension(demoProperties).getObjectVendorExtension()); |
| 74 | + ApiInfo apiInfo = |
| 75 | + new ApiInfoBuilder() |
| 76 | + .title(demoProperties.getApplicationName()) |
| 77 | + .description(demoProperties.getApplicationDescription()) |
| 78 | + .contact( |
| 79 | + new Contact( |
| 80 | + demoProperties.getApplicationName(), |
| 81 | + demoProperties.getApplicationDomain(), |
| 82 | + demoProperties.getApplicationSupport())) |
| 83 | + .license(demoProperties.getApplicationLicenseName()) |
| 84 | + .licenseUrl(demoProperties.getApplicationLicenseUrl()) |
| 85 | + .version(demoProperties.getApplicationVersion()) |
| 86 | + .termsOfServiceUrl(demoProperties.getApplicationLicenseUrl()) |
| 87 | + .extensions(apiInfoVendorExtensions) |
| 88 | + .build(); |
87 | 89 |
|
88 | | - return new Docket(DocumentationType.SWAGGER_2) |
89 | | - .protocols(protocols) |
90 | | - .apiInfo(apiInfo) |
91 | | - .produces(Collections.singleton(MediaType.APPLICATION_JSON)) |
92 | | - .consumes(Collections.singleton(MediaType.APPLICATION_JSON)) |
93 | | - .extensions(docketVendorExtensions) |
94 | | - .tags(new Tag("Speakers", "Speakers at Spring One Conference")) |
95 | | - .select() |
96 | | - .apis(RequestHandlerSelectors.basePackage(SpeakerResource.class.getPackage().getName())) |
97 | | - .paths(PathSelectors.any()) |
98 | | - .build(); |
99 | | -} |
| 90 | + return new Docket(DocumentationType.SWAGGER_2) |
| 91 | + .protocols(protocols) |
| 92 | + .apiInfo(apiInfo) |
| 93 | + .produces(Collections.singleton(MediaType.APPLICATION_JSON)) |
| 94 | + .consumes(Collections.singleton(MediaType.APPLICATION_JSON)) |
| 95 | + .extensions(docketVendorExtensions) |
| 96 | + .tags(new Tag("Speakers", "Speakers at Spring One Conference")) |
| 97 | + .select() |
| 98 | + .apis(RequestHandlerSelectors.basePackage(SpeakerResource.class.getPackage().getName())) |
| 99 | + .paths(PathSelectors.any()) |
| 100 | + .build(); |
| 101 | + } |
100 | 102 | } |
0 commit comments