/*
 * Copyright 2000-2017 Holon TDCN.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.holonplatform.jaxrs.swagger.spring;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.holonplatform.core.internal.Logger;
import com.holonplatform.jaxrs.spring.boot.resteasy.ResteasyConfigCustomizer;
import com.holonplatform.jaxrs.swagger.internal.SwaggerLogger;
import com.holonplatform.jaxrs.swagger.spring.internal.SwaggerJerseyConfiguration;
import com.holonplatform.jaxrs.swagger.spring.internal.SwaggerResteasyConfiguration;

import io.swagger.models.Swagger;

/**
 * Spring Boot Swagger auto-configuration class.
 * 
 * @since 5.0.0
 */
@Configuration
@ConditionalOnClass(Swagger.class)
@EnableConfigurationProperties(SwaggerConfigurationProperties.class)
@AutoConfigureBefore(name = "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration")
public class SwaggerAutoConfiguration {

	private final static Logger LOGGER = SwaggerLogger.create();

	@Configuration
	@ConditionalOnBean(type = "org.glassfish.jersey.server.ResourceConfig")
	static class EnableSwaggerJersey implements InitializingBean {

		@Bean
		public ResourceConfigCustomizer swaggerConfiguration(SwaggerConfigurationProperties configurationProperties) {
			return new SwaggerJerseyConfiguration(configurationProperties);
		}

		@Override
		public void afterPropertiesSet() throws Exception {
			LOGGER.debug(() -> "EnableSwaggerJersey initialized");
		}

	}

	@Configuration
	@ConditionalOnBean(type = "com.holonplatform.jaxrs.spring.boot.resteasy.ResteasyConfig")
	static class EnableSwaggerResteasy implements InitializingBean {

		@Bean
		public ResteasyConfigCustomizer swaggerConfiguration(SwaggerConfigurationProperties configurationProperties) {
			return new SwaggerResteasyConfiguration(configurationProperties);
		}

		@Override
		public void afterPropertiesSet() throws Exception {
			LOGGER.debug(() -> "EnableSwaggerResteasy initialized");
		}

	}

}

@@ -771,83 +771,8 @@
 re;%0A
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;%0A
 impo
@@ -1948,42 +1948,68 @@
 alOn
-Bean(type = %22org.glassfish
+Class(name = %22org.springframework.boot.autoconfigure
 .jersey.
 serv
@@ -2008,15 +2008,8 @@
 sey.
-server.
 Reso
@@ -2014,24 +2014,34 @@
 sourceConfig
+Customizer
 %22)%0A%09static c
@@ -2457,16 +2457,17 @@
 alOn
-Bean(typ
+Class(nam
 e = 
@@ -2526,16 +2526,26 @@
 syConfig
+Customizer
 %22)%0A%09stat

Fix autoconfig conditions