Reputation: 81
I have setup a base context-path for my spring boot 3 application and I am using spring-doc to display documentation in a swagger-ui. However, when deployed my apps url path gets prefixed with /service-api
. This causes a problem when trying to view my swagger-ui documentation in the browser because it cant load the swagger.json for the ui. I can override the url with springdoc.swagger-ui.url: /service-api/api/service/swagger.json
. However, I get this url when I load the swagger ui from my browser:
/api/service/service-api/api/service/swagger.json
. But, I need it display: /service-api/api/service/swagger.json
. I think the context-path is getting appended by default to the path I have setup in my application.yaml. Is there a way to disable context-path from getting appended in the swagger-ui?
Here is my applications.yaml
# Server
server:
port: 9000
servlet:
context-path: /api/service
application-display-name: service-api
# Spring Doc
springdoc:
swagger-ui:
path: /swagger
disable-swagger-default-url: true
url: /service-api/api/service/swagger.json
api-docs:
path: /swagger.json
Here are my dependancies:
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
I have also tried setting with springdoc.swagger-ui.configUrl
. But, I just get an empty url in the swagger ui when using configUrl.
Upvotes: 1
Views: 1128
Reputation: 234
try this in your application.yaml file
spring:
mvc:
pathmatch:
matching-strategy: ANT_PATH_MATCHER
use io.springfox librabry instead of io.swagger.core.v3 you can get it from https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/3.0.0
Upvotes: 1