Skip to content

Failed to load API definition on URL /v3/api-docs/ (HTTP 404 not found error) #2332

Closed
@rasenderhase

Description

@rasenderhase

Describe the bug

image

The swagger-ui frontend tries to load the openapi data from the URL

/v3/api-docs/ with trailing slash.

The backend resource OpenApiWebMvcResource listens per default on /v3/api-docs without trailing slash.

In fact, the URL /v3/api-docs/ gets mapped wrongly by Spring:

2023-08-03 14:28:42,652 DEBUG [http-nio-8080-exec-1][][] o.s.s.w.FilterChainProxy: Secured GET /v3/api-docs/
2023-08-03 14:28:42,657 DEBUG [http-nio-8080-exec-1][][] o.s.w.s.DispatcherServlet: GET "/my-application/v3/api-docs/", parameters={}
2023-08-03 14:28:44,604 DEBUG [http-nio-8080-exec-1][][] o.s.w.s.h.SimpleUrlHandlerMapping: Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-08-03 14:28:45,977 DEBUG [http-nio-8080-exec-1][][] o.s.w.s.r.ResourceHttpRequestHandler: Resource not found

So the frontend displays the error response status is 404 /my-application/v3/api-docs/.

I am using...

 org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0
 org.springframework.boot:spring-boot-gradle-plugin:3.1.2

Maybe the issue is caused by this change in Spring:

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.html#setUseTrailingSlashMatch(java.lang.Boolean)

The Spring framework is now more precise per default handling URLs. I think the controller that is providing the swagger-config should be adapted. Currently it adds a trailing slash to the 1st url in the urls array:

{
    "configUrl": "/my-application/v3/api-docs/swagger-config",
    "defaultModelExpandDepth": "10",
    "defaultModelRendering": "model",
    "defaultModelsExpandDepth": "-1",
    "docExpansion": "full",
    "oauth2RedirectUrl": "http://127.0.0.1:16071/my-application/swagger-ui/oauth2-redirect.html",
    "urls": [
        {
            "url": "/my-application/v3/api-docs/",
            "name": ""
        },
        {
            "url": "/my-application/v3/api-docs/api",
            "name": "api"
        }
    ],
    "validatorUrl": ""
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions