0

I need to use a specific url for Swagger-ui. I have tried to use the property "springdoc.swagger-ui.path" but it only redirects.

application.propperties: springdoc.swagger-ui.path=/helloWorld/swagger

Url in browser: http://localhost:8181/helloWorld/swagger

but the url changes to the following when hits enter button:

http://localhost:8181/manager/swagger-ui/index.html?configUrl=/manager/swagger/swagger.json/swagger-config

the question is, how can i make the path be only http://localhost:8181/helloWorld/swagger/index.html or http://localhost:8181/helloWorld/swagger once i've hit enter (I need the word "swagger-ui" and configUrl disappear)?

I`m uisng Springdoc and even tried with springfox

Pom.xml

  <dependency>
         <groupId>org.springdoc</groupId>
         <artifactId>springdoc-openapi-ui</artifactId>
         <version>1.5.2</version>
    </dependency>

application.propperties:

springdoc.api-docs.path=/helloWorld/swagger/swagger.json
springdoc.swagger-ui.path=/helloWorld/swagger
FireStarter
  • 43
  • 2
  • 7
  • Does this answer your question? [I have installed OpenAPI 3 using springdoc, but the URL is strange. Can I change it to the expected value?](https://stackoverflow.com/questions/65820916/i-have-installed-openapi-3-using-springdoc-but-the-url-is-strange-can-i-change) – Debargha Roy Mar 03 '21 at 09:41

1 Answers1

-2

I guess it's version dependent regarding the answer.

if you're using 2.8.0 and above, you could use following dependencies:

        <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.8.0</version>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.8.0</version>
    </dependency>

And create a controller which will just redirect to the main swagger page, like this:

    @Controller
public class SwaggerController {

    @RequestMapping("/")
    public String index() {
        return "redirect:swagger-ui.html";
    }
}

But if you use 2.6.1 or like that you can personalize your swagger configuration java class extending WebMvcConfigurerAdapter and overwriting the addViewController, like this:

@Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController(MAIN_URL, SWAGGER_UI_URL).setContextRelative(true);
        registry.addRedirectViewController(MAIN_URL + "/", SWAGGER_UI_URL).setContextRelative(true);
    }

That's it. Both approaches used the same dependencies but with different versions.

ekimike
  • 9
  • 2