Skip to content

Springdoc does not work with Spring's "capture the rest" PathPattern syntax #2383

Closed
@quinncaster

Description

@quinncaster

Describe the bug

Also on stackoverflow.com here:
https://stackoverflow.com/questions/77129312/springdoc-2-2-0-latest-does-not-work-with-springs-capture-the-rest-pathpatt

Since 5.0, Spring supports a path parser known as "PathPattern", it's recommended for many reasons
https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc

There is a "capture the rest" syntax to capture an entire path (all segments) as documented here:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/util/pattern/PathPattern.html

We can see how this is used/tested here:
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java

The following Spring Boot MVC snippet shows the situation. Unfortunately, I am required to support this endpoint as defined (for legacy reasons), so changing the "protocol" is not an option. My goal is to enable OpenDoc/Swagger.

...
	@GetMapping("context/{*pathVar}")
	@Operation(summary ="operate on the data passed in the path")
	public String operate(@PathVariable String pathVar) { 
	... 
	}
...

Here are my observations:

Spring Doc Failing / App Working:

  • If I leave the '*' in "{*pathVar}" so it is like "{*pathVar}", then SpringDoc appears to generate working doc, but execution of the swagger fails.
  • GOOD: My application can accept any input with slashes (ex: a longer url, like /context/part1/part2/part3)
  • BAD: In this case, when I paste-in a string into the swagger page, it is not sent to the server, instead I see: https://server.com/context/%7B*pathVar%7D
  • So, I can not use springdoc/swagger to call/demo this endpoint.

Spring Doc Working / App Failing:

  • If I remove the '*' from "{*pathVar}" so it is like "{pathVar}", then SpringDoc generates working doc.
  • GOOD: In this case, I can paste-in any string into the swagger page, and it is properly sent to the server, like: https://server.com/context/part1/part2
  • BAD: My application is not invoked, because Spring will not accept any input with slashes.

Summary:

It seems that SpringDoc is somehow stumbling on the so-called "capture the rest" syntax, and building the URL from the exact syntax instead of building the URL from what was captured by the "capture the rest" syntax.

I've tried many variations of the syntax options, and likewise tried reviewing springdoc configuration options but so far I have not found a solution that both allows my application to work, and also be demoed via SpringDoc/Swagger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions