3

After following @Zagrebin-Victor advice, I have a Spring MVC project running OpenAPI 3 (springdoc-openapi-1.5.3)

Following this FAQ I defined this on a property file:

springdoc.swagger-ui.disable-swagger-default-url=true

So no "Petstore API" is loaded by default.

Now, I would like to configure some of the properties documented on Swagger-ui configuration web ("urls" property, for example). And that is the problem, I can not figure out how to configure the project

Not working if property put on:

  1. "src/main/resources/application.properies" (though my application is not a Spring Boot one)
  2. "src/main/resources/swagger-config.yaml"
  3. Neither putting it as environment variable by code (ugly solution)

I found, and tried, another property notation as documented on this GitHub thread. But no luck

Any idea?

Thank you very much

P.S: I do not want to configure swagger-ui putting parameters on the URL

floss.dev
  • 81
  • 6

1 Answers1

0

What finally worked for me with this problem was to skip any "properties" or "yaml" entirely. Instead I defined properties beans explicitly in the configuration class where the OpenAPI bean is provided:

public class OpenApiConfig {
      // ...
      // ...
      // ...

      @Bean
      public OpenAPI accOpenApi() {
          return new OpenAPI()
                  .info(apiInfo);
      }

      @Bean
      public SpringDocConfigProperties springDocConfigProperties() {
          SpringDocConfigProperties props = new SpringDocConfigProperties();
          props.setPackagesToScan(List.of("x.y.z"));
          props.setPathsToMatch(List.of("/api/**"));
          return props;
      }

      @Bean
      public SwaggerUiConfigProperties SwaggerUiConfigProperties() {
          SwaggerUiConfigProperties props = new SwaggerUiConfigProperties();
          props.setDisableSwaggerDefaultUrl(true);
          props.setDisplayRequestDuration(true);
          props.setTryItOutEnabled(true);
          props.setPath("/my-path-to/index.html");
          return props;
      }
}

I do not have @Configuration on top of this class, because I reference (and create) it from the xml configuration for the servlet context.

Googie
  • 5,742
  • 2
  • 19
  • 31