View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.catalog.config;
18  
19  import org.springframework.context.annotation.Bean;
20  import org.springframework.context.annotation.Configuration;
21  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
22  import springfox.documentation.builders.ApiInfoBuilder;
23  import springfox.documentation.builders.PathSelectors;
24  import springfox.documentation.builders.RequestHandlerSelectors;
25  import springfox.documentation.service.ApiInfo;
26  import springfox.documentation.spi.DocumentationType;
27  import springfox.documentation.spring.web.plugins.Docket;
28  import springfox.documentation.swagger2.annotations.EnableSwagger2;
29  
30  import java.time.LocalDate;
31  import java.time.LocalDateTime;
32  
33  /**
34   * This will configure Swagger to produce an API for all of our REST endpoints.
35   */
36  @Configuration
37  @EnableSwagger2
38  @EnableWebMvc
39  public class SwaggerConfig {
40      @Bean
41      public Docket api() {
42          return new Docket(DocumentationType.SWAGGER_2)
43              .apiInfo(apiInfo())
44              .select()
45              .apis(RequestHandlerSelectors.any())
46              .paths(PathSelectors.any())
47              .build()
48              .directModelSubstitute(LocalDate.class, java.sql.Date.class)
49              .directModelSubstitute(LocalDateTime.class, java.util.Date.class);
50      }
51  
52      private ApiInfo apiInfo() {
53          return new ApiInfoBuilder()
54                  .title("Catalog Service")
55                  .description("Maintains the audit event catalog")
56                  .termsOfServiceUrl("http://logging.apache.org")
57                  .contact("Apache Logging")
58                  .license("1.0")
59                  .licenseUrl("http://www.apache.org/licenses/")
60                  .version("1.0")
61                  .build();
62      }
63  }