Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-7878

Swagger's base.path should be calculated rather than hardcoded

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.14.0
    • 2.15.0
    • camel-swagger
    • None
    • Unknown

    Description

      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:

      @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")); 
              } 
      } 
      

      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.

              /** 
               * 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; 
              } 
      

      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

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            mraible Matt Raible
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: