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

Trailing slash causes 500 when loading /swagger-ui/ #2235

Closed
wtell400 opened this issue May 19, 2023 · 3 comments
Closed

Trailing slash causes 500 when loading /swagger-ui/ #2235

wtell400 opened this issue May 19, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@wtell400
Copy link

Describe the bug

Given

  • Spring Boot 3.0.2 (using default for PathMatchConfigurer.setUseTrailingSlashMatch(boolean))
  • springdoc-openapi 2.1.0

springdoc.api-docs.enabled=true
springdoc.api-docs.path=/api/docs
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.path=/api/docs/swagger-ui

When
accessing swagger-ui using:
https://myhost/api/docs -> loads openapi json
https://myhost/api/docs/ -> 404 (expected)
https://myhost/api/docs/swagger-ui -> redirects to https://myhost/api/docs/swagger-ui/index.html, loads swagger-ui
https://myhost/api/docs/swagger-ui/ -> 500 (unexpected)

java.lang.StringIndexOutOfBoundsException: begin 11, end 10, length 10
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4604)
	at java.base/java.lang.String.substring(String.java:2707)
	at java.base/java.lang.String.substring(String.java:2680)
	at org.springdoc.ui.AbstractSwaggerResourceResolver.path(AbstractSwaggerResourceResolver.java:71)
	at org.springdoc.ui.AbstractSwaggerResourceResolver.findWebJarResourcePath(AbstractSwaggerResourceResolver.java:42)
	at org.springdoc.webmvc.ui.SwaggerResourceResolver.resolveResource(SwaggerResourceResolver.java:33)
	at org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:75)
...<lots of calls unrelated to sprindoc>...

To Reproduce
See the webmvc demo site:

http://144.24.171.248:8081/ -> redirects to http://144.24.171.248:8081/swagger-ui/index.html, loads swagger-ui
http://144.24.171.248:8081/swagger-ui -> 500
http://144.24.171.248:8081/swagger-ui/ -> 500

Expected behavior

https://myhost/api/docs/ -> 404
https://myhost/api/docs/swagger-ui/ -> 404

Additional context
Might be related to Spring MVC and WebFlux URL Matching Changes which now sees /resources/ and /resources as separate endpoints.

@sanketmeghani
Copy link

I think 2203 and this one are related

@ctmay4
Copy link

ctmay4 commented May 26, 2023

I am see the same bug.

uc4w6c added a commit to uc4w6c/springdoc-openapi that referenced this issue May 27, 2023
uc4w6c added a commit to uc4w6c/springdoc-openapi that referenced this issue May 27, 2023
uc4w6c added a commit to uc4w6c/springdoc-openapi that referenced this issue May 27, 2023
bnasslahsen added a commit that referenced this issue May 31, 2023
…tion_v2

fix StringIndexOutOfBoundsException when path is same webjar. #2235
bnasslahsen added a commit that referenced this issue May 31, 2023
…tion

fix StringIndexOutOfBoundsException when path is same webjar. #2235
@bnasslahsen
Copy link
Contributor

Resolved by #2235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants