Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger UI does not work after passing from 2.9.2 to 3.0.0 #3441

Closed
pbarsotti-glovo opened this issue Jul 23, 2020 · 11 comments
Closed

Swagger UI does not work after passing from 2.9.2 to 3.0.0 #3441

pbarsotti-glovo opened this issue Jul 23, 2020 · 11 comments

Comments

@pbarsotti-glovo
Copy link

After upgrading the version to the latest (3.0.0) I receive a 404 when I try to access to http://localhost:8080/swagger-ui.html.

My config details are:

// Spring boot gradle plugin
id 'org.springframework.boot' version '2.3.1.RELEASE'

// Swagger deps
implementation('io.springfox:springfox-swagger2:3.0.0')
implementation('io.springfox:springfox-swagger-ui:3.0.0')
@Configuration
@EnableSwagger2
public class AppConfig {
    @Bean
    public Docket apiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
    }
}
@dilipkrish
Copy link
Member

Please read the migration docs. NOTE: that swagger-ui location has changed.

Let me summarize the changes for you here, you could do one of two things for swagger-ui to show up. It looks like you have a spring boot app, so just replace the two springfox dependencies with springfox-boot-starter:3.0.0 and remove the @EnableSwagger2 annotation and you should be good to go. Otherwise implement a WebMvcConfigurer and register resource handlers for swagger-ui for it to work.

@dilipkrish dilipkrish added this to the 3.0.1 milestone Jul 23, 2020
@pbarsotti-glovo
Copy link
Author

Thanks for the response Dilip.
I forgot to mention that I already tried using the two methods mentioned in the migration doc.
The endpoint with the definition works fine (http://localhost:8080/v2/api-docs) but the UI still returns a 404.

@dilipkrish
Copy link
Member

If you tried the two methods, then you should've seen the swagger-ui @ http://localhost:8080/swagger-ui/index.html and not the url you mentioned in the issue.

@pbarsotti-glovo
Copy link
Author

Ohh, that's the problem! I was using an old bookmarked url...
Sorry to bother you with such a stupid thing and thanks for your time.

@dilipkrish
Copy link
Member

Mystery solved 🧐🕵️

@lincze
Copy link

lincze commented Sep 27, 2020

Have the same issue. i have a pretty common spring-boot mvn app, which used happily the springfox swagger 2.9.2 packages: in maven deps:

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-bean-validators</artifactId>
            <version>2.9.2</version>
        </dependency>

It worked perfectly on test url http://localhost:8080/swagger-ui.html

Then tried to upgrade to 3.0.0 with these steps:

  • removed all three above 2.9.2 dependencies
  • added spring boot starter dependency:
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
  • removed @EnableSwagger2 annotations

When I access the http://localhost:8080/swagger-ui/ url, I get some weird error, here is the log:

2020-09-27 05:36:21.076 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui/", parameters={}
2020-09-27 05:36:21.098 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : "FORWARD" dispatch for GET "/swagger-ui/index.html", parameters={}
2020-09-27 05:36:21.103  WARN 176461 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
2020-09-27 05:36:21.103 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from "FORWARD" dispatch, status 405
2020-09-27 05:36:21.107 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 405 METHOD_NOT_ALLOWED
2020-09-27 05:36:21.111 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2020-09-27 05:36:21.144 DEBUG 176461 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 405

@lincze
Copy link

lincze commented Sep 27, 2020

Note, that behind the scenes the swagger schemes mostly are setup

  • ... Adding key: /swagger-resources/configuration/security, WebMvcRequestHandler{requestMapping={GET /swagger-resources/configuration/security, produces [application/json]}, handlerMethod=springfox.documentation.swagger.web.ApiResourceController#securityConfiguration(), ...
  • ... Adding key: /swagger-resources/configuration/ui, WebMvcRequestHandler{requestMapping={GET /swagger-resources/configuration/ui, produces [application/json]}, handlerMethod=springfox.documentation.swagger.web.ApiResourceController#uiConfiguration(), ...
  • ... Adding key: /v2/api-docs, WebMvcRequestHandler{requestMapping={GET /v2/api-docs, produces [application/json || application/hal+json]}, handlerMethod=springfox.documentation.swagger2.web.Swagger2ControllerWebMvc#getDocumentation(String, HttpServletRequest), ...
  • ... Adding key: /v3/api-docs, WebMvcRequestHandler{requestMapping={GET /v3/api-docs, produces [application/json || application/hal+json]}, handlerMethod=springfox.documentation.oas.web.OpenApiControllerWebMvc#getDocumentation(String, HttpServletRequest), ...

e.g. GET /swagger-resources/configuration/ui gives:

{
  "deepLinking": true,
  "displayOperationId": false,
  "defaultModelsExpandDepth": 1,
  "defaultModelExpandDepth": 1,
  "defaultModelRendering": "example",
  "displayRequestDuration": false,
  "docExpansion": "none",
  "filter": false,
  "operationsSorter": "alpha",
  "showExtensions": false,
  "showCommonExtensions": false,
  "tagsSorter": "alpha",
  "validatorUrl": "",
  "supportedSubmitMethods": [
    "get",
    "put",
    "post",
    "delete",
    "options",
    "head",
    "patch",
    "trace"
  ],
  "swaggerBaseUiUrl": ""
}

juat, the /swagger-ui/ path is not mapped to a handler

@lincze
Copy link

lincze commented Sep 27, 2020

This was a false alarm. I've found a controller request mapping with the antipattern "/{xxx}/...." - - that caused the error.

@stale
Copy link

stale bot commented Dec 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Dec 26, 2020
@stale
Copy link

stale bot commented Jan 9, 2021

This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.

@stale stale bot closed this as completed Jan 9, 2021
@AjayPulapa
Copy link

It is not working
Above API's are working but it is not showing entire documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants