/
SwaggerConfig.java
40 lines (34 loc) · 1.51 KB
/
SwaggerConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.raibledesigns.camel.config;
import org.apache.camel.component.swagger.DefaultCamelSwaggerServlet;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class SwaggerConfig implements EnvironmentAware {
private RelaxedPropertyResolver propertyResolver;
@Override
public void setEnvironment(Environment environment) {
this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger.");
}
/**
* Swagger Camel Configuration
*/
@Bean
public ServletRegistrationBean swaggerServlet() {
ServletRegistrationBean swagger = new ServletRegistrationBean(new DefaultCamelSwaggerServlet(), "/api-docs/*");
Map<String, String> params = new HashMap<>();
params.put("base.path", "http://localhost:8080/api");
params.put("api.title", propertyResolver.getProperty("title"));
params.put("api.description", propertyResolver.getProperty("description"));
params.put("api.termsOfServiceUrl", propertyResolver.getProperty("termsOfServiceUrl"));
params.put("api.license", propertyResolver.getProperty("license"));
params.put("api.licenseUrl", propertyResolver.getProperty("licenseUrl"));
swagger.setInitParameters(params);
return swagger;
}
}