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

Given empty pathvariable value and get 500 internal server error #2203

Closed
LinhaoJiaTomo opened this issue Apr 12, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@LinhaoJiaTomo
Copy link

LinhaoJiaTomo commented Apr 12, 2023

Describe the bug
We have an api like

@GetMapping("/xxx/{id}")
fun retrieveXxxById(@PathVariable id: String)

And when we call this api using /xxx and not give the PathVariable id, we'll get 500 error, this issue happens when we update our org.springdoc:springdoc-openapi-kotlin from 1.6.15 to 1.7.0, it used to throw 404 from our logic.
Our configuration of springdoc is

springdoc:
  webjars:
    prefix: ''
  swagger-ui:
    disable-swagger-default-url: true
    operationsSorter: method
    tagsSorter: alpha
  api-docs:
    enabled: true

And the exception detail is

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(Unknown Source)
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Original Stack Trace:
		at java.lang.String.substring(Unknown Source)
		at org.springdoc.ui.AbstractSwaggerResourceResolver.path(AbstractSwaggerResourceResolver.java:71)
		at org.springdoc.ui.AbstractSwaggerResourceResolver.findWebJarResourcePath(AbstractSwaggerResourceResolver.java:42)
		at org.springdoc.webflux.ui.SwaggerResourceResolver.resolveResource(SwaggerResourceResolver.java:35)
		at org.springframework.web.reactive.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:75)
		... 148 frames truncated

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    2.7.10
  • What modules and versions of springdoc-openapi are you using?
    org.springdoc:springdoc-openapi-webflux-ui:1.7.0, org.springdoc:springdoc-openapi-kotlin:1.7.0

Expected behavior
Not return 500

@sanketmeghani
Copy link

I am also getting similar error while accessing /swagger-ui/.

@Martin01248
Copy link

Martin01248 commented May 23, 2023

I am also having this issue that /swagger-ui leads to StringIndexOutOfBoundsException: String index out of range: -1 resulting in 500 server error.

Class AbstractSwaggerResourceResolver
with method

	private String path(String webjar, String path) {
		if (path.startsWith(webjar)) {
			path = path.substring(webjar.length() + 1);
		}
		return path;
	}

where parameters are
webjar="swagger-ui"
path="swagger-ui"
results in
StringIndexOutOfBoundsException: String index out of range: -1

@uc4w6c
Copy link
Collaborator

uc4w6c commented May 27, 2023

i think this will fix it. #2244

@bnasslahsen
Copy link
Collaborator

Fixed by #2235

@bnasslahsen bnasslahsen added the bug Something isn't working label Jun 2, 2023
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

5 participants