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

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

Closed
rasenderhase opened this issue Aug 3, 2023 · 9 comments

Comments

@rasenderhase
Copy link

rasenderhase commented Aug 3, 2023

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": ""
}
@uc4w6c
Copy link
Collaborator

uc4w6c commented Aug 5, 2023

Please provide a Minimal, Reproducible Example - with HelloController that reproduces the issue.

@rasenderhase
Copy link
Author

I have created a demo project. And of course it works... ;-)

However, the response of http://localhost:8080/v3/api-docs/swagger-config looks different in the demo project:

{
    "configUrl": "/v3/api-docs/swagger-config",
    "oauth2RedirectUrl": "http://localhost:8080/swagger-ui/oauth2-redirect.html",
    "url": "/v3/api-docs",
    "validatorUrl": ""
}

In the project with the issue, the property url is not present, instead there is the property urls which is an array. How can I achieve that in the demo project? Maybe that is causing the issue...?

@rasenderhase
Copy link
Author

I have added the OpenApiConfig we are using, and that introduces the issue. see rasenderhase/demo-api-docs-issue@d5e2266

@uc4w6c
Copy link
Collaborator

uc4w6c commented Aug 5, 2023

Thank you.
But it returns 404.
private repository?

@rasenderhase
Copy link
Author

Now it's public. Sorry for that.

@bnasslahsen
Copy link
Contributor

@rasenderhase,

The group Name cannot be null or empty.
I have updated the rule for the future release so there is no misunderstanding.

@EdgardHernandezp
Copy link

EdgardHernandezp commented Nov 17, 2023

I'm having the same problem, apparently this was closed and fixed but I don't understand whats the workaround. I'm using version 2.2.0
image

@rasenderhase
Copy link
Author

rasenderhase commented Nov 17, 2023

If you are using config, check if the group name is empty. That is not allowed:

@Bean
public GroupedOpenApi all() {
    return createDefaultGroupedOpenApi("", "/**");
}

@EdgardHernandezp
Copy link

EdgardHernandezp commented Nov 17, 2023

I understand but in my case all I did was add the dependency and exclude from the authorization flow this paths:

/swagger-ui.html
/swagger-ui/**
/v3/api-docs/**
/v3/api-docs.yaml
/swagger-resources
/swagger-resources/**
/configuration/ui
/configuration/security
/swagger-ui/**
/webjars/**

I have not made any extra swagger related config. At this point it should be working :(

rasenderhase referenced this issue in rasenderhase/demo-api-docs-issue Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants