package hello;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.web.Swagger2Controller;

import static springfox.documentation.spi.DocumentationType.SWAGGER_2;

/**
 * {@code SwaggerConfiguration} sets up top-level Swagger configuration such
 * as API display properties.  Provide configuration with the "swagger.api"
 * block in properties or YAML.  To wit: <table><tr><th>Property</th>
 * <th>Purpose</th></tr> <tr><td>{@code swagger.api.title}</td> <td>API
 * Title</td></tr> <tr><td>{@code swagger.api.description}</td> <td>API
 * Description</td></tr> <tr><td>{@code swagger.api.terms-of-service.url}</td>
 * <td>API Terms of Service</td></tr> <tr><td>{@code swagger.api.contact.email-address}</td>
 * <td>API Contact</td></tr> <tr><td>{@code swagger.api.license.name}</i></td>
 * <td>API License Name, <i>e.g.</i>, "Public Domain"</td></tr> <tr><td>{@code
 * swagger.api.license.url}</td> <td>API License</td></tr> <tr><td>{@code
 * swagger.api.version}</td> <td>API Version</td></tr></table>
 *
 * @author <a href="mailto:boxley@thoughtworks.com">Brian Oxley</a>
 */
@Configuration
@ConditionalOnClass(Swagger2Controller.class)
public class SwaggerConfiguration {
    @Bean
    public Docket setupSwaggerApi(final Environment env) {
        return new Docket(SWAGGER_2).apiInfo(
                new ApiInfo(env.getProperty("swagger.api.title"),
                        env.getProperty("swagger.api.description"),
                        env.getProperty("swagger.api.version"),
                        env.getProperty("swagger.api.terms-of-service.url"),
                        env.getProperty("swagger.api.contact.email-address"),
                        env.getProperty("swagger.api.license.name"),
                        env.getProperty("swagger.api.license.url")));
    }
}

@@ -418,16 +418,55 @@
 oller;%0A%0A
+import static java.util.Arrays.asList;%0A
 import s
@@ -1649,16 +1649,8 @@
 _2).
-apiInfo(
 %0A   
@@ -1662,16 +1662,24 @@
         
+apiInfo(
 new ApiI
@@ -2072,24 +2072,24 @@
 nse.name%22),%0A
-
             
@@ -2144,16 +2144,626 @@
 .url%22)))
+.%0A                select().paths(SwaggerConfiguration::notManagement).%0A                build();%0A    %7D%0A%0A    /** @todo How to automate? */%0A    private static boolean notManagement(final String path) %7B%0A        if (path.startsWith(%22/env/%22) %7C%7C path.startsWith(%22/metrics/%22))%0A            return false;%0A        return !asList(%22/%22, %22/archaius%22, %22/autoconfig%22, %22/beans%22,%0A                %22/configprops%22, %22/dump%22, %22/env%22, %22/error%22, %22/health%22,%0A                %22/heartbeat%22, %22/info%22, %22/metrics%22, %22/mappings%22, %22/pause%22,%0A                %22/refresh%22, %22/resume%22, %22/restart%22, %22/shutdown%22, %22/trace%22)%0A                .contains(path)
 ;%0A    %7D%0A

Exclude management endpoints from Swagger.