You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2014/12/24 13:15:13 UTC

[jira] [Updated] (CAMEL-7878) Swagger's base.path should be calculated rather than hardcoded

     [ https://issues.apache.org/jira/browse/CAMEL-7878?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen updated CAMEL-7878:
-------------------------------
    Fix Version/s: 2.15.0

> Swagger's base.path should be calculated rather than hardcoded
> --------------------------------------------------------------
>
>                 Key: CAMEL-7878
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7878
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-swagger
>    Affects Versions: 2.14.0
>            Reporter: Matt Raible
>            Assignee: Willem Jiang
>             Fix For: 2.15.0
>
>
> The "base.path" has to be configured or calling the methods by clicking on buttons in Swagger UI doesn't work. With Spring Boot, I'm able to configure Swagger with the following: 
> {code}
> @Configuration 
> @EnableSwagger 
> public class SwaggerConfig implements EnvironmentAware { 
>         public static final String DEFAULT_INCLUDE_PATTERN = "/api/.*"; 
>         private RelaxedPropertyResolver propertyResolver; 
>         @Override 
>         public void setEnvironment(Environment environment) { 
>                 this.propertyResolver = new RelaxedPropertyResolver(environment, "swagger."); 
>         } 
>         /** 
>          * Swagger Spring MVC configuration 
>          */ 
>         @Bean 
>         public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) { 
>                 return new SwaggerSpringMvcPlugin(springSwaggerConfig) 
>                                 .apiInfo(apiInfo()) 
>                                 .genericModelSubstitutes(ResponseEntity.class) 
>                                 .includePatterns(DEFAULT_INCLUDE_PATTERN); 
>         } 
>         /** 
>          * API Info as it appears on the swagger-ui page 
>          */ 
>         private ApiInfo apiInfo() { 
>                 return new ApiInfo( 
>                                 propertyResolver.getProperty("title"), 
>                                 propertyResolver.getProperty("description"), 
>                                 propertyResolver.getProperty("termsOfServiceUrl"), 
>                                 propertyResolver.getProperty("contact"), 
>                                 propertyResolver.getProperty("license"), 
>                                 propertyResolver.getProperty("licenseUrl")); 
>         } 
> } 
> {code}
> With Camel, it's a bit less code, but if I don't override the "base.path", it defaults to localhost:8080. The Spring MVC Swagger implementation figures out the correct base path on its own. 
> {code}
>         /** 
>          * Swagger Camel Configuration 
>          */ 
>         @Bean 
>         public ServletRegistrationBean swaggerServlet() { 
>                 ServletRegistrationBean swagger = new ServletRegistrationBean(new SpringRestSwaggerApiDeclarationServlet(), "/swagger/*"); 
>                 Map<String, String> params = new HashMap<>(); 
>                 params.put("base.path", "https://localhost:8443/rest"); 
>                 params.put("api.title", propertyResolver.getProperty("title")); 
>                 params.put("api.description", propertyResolver.getProperty("description")); 
>                 params.put("api.termsOfServiceUrl", propertyResolver.getProperty("termsOfServiceUrl")); 
>                 params.put("api.version", propertyResolver.getProperty("version")); 
>                 params.put("api.license", propertyResolver.getProperty("license")); 
>                 params.put("api.licenseUrl", propertyResolver.getProperty("licenseUrl")); 
>                 swagger.setInitParameters(params); 
>                 return swagger; 
>         } 
> {code}
> Is it possible to improve the SpringRestSwaggerApiDeclarationServlet so it gets the path from CamelServlet and it doesn't have to be hardcoded? 
> Mailing list thread: 
> http://camel.465427.n5.nabble.com/Camel-s-Swagger-vs-Spring-MVC-Swagger-td5757023.html



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)