Spring-Doc open api not working with Spring cloud config server @EnableConfigServer

2k views Asked by At

Im using spring boot 2.3.2.RELEASE with spring-cloud-config-server 2.2.4.RELEASE. Im trying to implement the spring-doc-openapi (1.4.3) in a existing project. If i add @EnableConfigServer in one the configuration class file, the swagger-ui.html endpoint returns a weird json:

   "name":"swagger-ui",
   "profiles":[
      "index.html"
   ],
   "label":null,
   "version":null,
   "state":null,
   "propertySources":[

   ]
}

and not the the swagger ui as expected. Im not sure if its a bug, but would appreciate any kind of help.

2

There are 2 answers

0
Piotr Kupczyk On

Answer from @brianbro seems not to be working anymore...

Verified on: springdoc-openapi v1.6.6 and org.springframework.cloud:spring-cloud-config-server:v2.2.4.RELEASE

Here is how I solved it:

  1. List item spring.cloud.config.server.prefix=config-server - please note that any request to config server will require to add prefix!

  2. Add following bean (sample implementation in Kotlin)

    @Bean fun configServerApi(): GroupedOpenApi =
    GroupedOpenApi.builder()
        .group("Config server")
        .pathsToMatch(
            "/config-server/**"
        )
        .build()
    

Now you should be able to reach swagger ui :)

1
brianbro On

Not sure if its relevant to add the springdoc dependency on spring cloud config server, unless you need to explore some APIs on the config server it self.

Here is the link of a fully working example using springdoc with config server:

And this is the link of a blog which explains the natural usage with microservies and spring cloud modules: