I have a bunch of REST APIs accessible under a certain domain, let's call it mydomain.com
. The REST endpoints themselves are of form mydomain.com/sys1/api/v1/data
, mydomain.com/sys2/api/v1/coi/foruser/{user}
, etc. and they must stay that way.
When accessing mydomain.com
, I am served the Swagger UI page, such that my address bar reads mydomain.com/swagger-ui.html
. My goal is to have the UI be launched from a custom directory, e.g customDir
, WITHOUT affecting the API endpoints. So, when I access mydomain.com
, I want my address bar to read mydomain.com/customDir/swagger-ui.html
. I need to do this for security reasons related to my organization; we want to control access to our Swagger UI so that it's viewed only by appropriately authorized users, so we intend to protect customDir
under specific access groups.
For users of Springfox Swagger 3.0.0, like us, the top-voted answer in this 2020 SO post references a discussion on the Springfox GitHub, where it is suggested that the following is added to the application.yml
:
springfox:
documentation:
swaggerUi:
baseUrl: /customDir
openApi:
v3:
path: /customDir/v3/api-docs
swagger:
v2:
path: /customDir/v2/api-docs
Unfortunately, when attempting this fix, I get an "Unable to infer base url" popup that keeps popping up no matter what I type:
This 2017 SO post's accepted solution suggests that one moves the @EnableSwagger2
annotation from the configuration class to the central @SpringBootApplication
- annotated class, but this has not worked for me; I am still getting that error.
pom
dependencies of interest:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
And my application.yml
:
spring:
application:
name: case-api-gateway
cloud:
gateway:
globalcors:
cors-configurations:
'[/**]':
allowedOrigins: "*"
allowedMethods:
- GET
- POST
- PUT
- DELETE
management:
health.jms.enabled: false
info.env.enabled: true
endpoint:
health:
show-details: ALWAYS
endpoints:
web:
base-path: /
exposure.include: info, health, status
server:
port: 8084
logging:
file:
name: ${APP_LOG_PATH:/tmp}/rcm.log
pattern:
level: "%5p %8X{user} %36X{acid}"