swagger-api / swagger-api/swagger-ui

Spring WebFlux PathPatternParser syntax in mapping annotation is passed verbatim to the PathVariable

Open
#8,466 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: macOS
  • Browser: chrome
  • Version: 110.0.5481.177
  • Method of installation: maven
  • Swagger-UI version: 4.15.5 (via springdoc-openapi-webflux-ui 1.6.14)
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
  <version>2.7.8</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webflux-ui</artifactId>
  <version>1.6.14</version>
</dependency>

Example Swagger/OpenAPI definition:
n/a

Swagger-UI configuration options:

springdoc.packages-to-scan=com.example.foobar.rest
springdoc.swagger-ui.operationsSorter=alpha
springdoc.swagger-ui.tagsSorter=alpha
springdoc.swagger-ui.doc-expansion=none
springdoc.webjars.prefix=
Describe the bug you're encountering

When using the Spring 5 PathPatternParser multiple segment matching syntax (/{*path}) in a WebFlux app (maybe a regular Spring Web too if configured to use it) with a @GetMapping or @RequestMapping, the literal path variable ({*path}) is sent to the @PathVariable when invoked through Swagger UI. It works as expected from the browser address bar via a simple URL GET.

The path pattern parser syntax is defined here and more examples shown here.

Create a simple @RestController with the following method:

@GetMapping(path = "/{*path}", produces = MediaType.TEXT_PLAIN_VALUE)
public Mono<String> pathMatching(@PathVariable String path) {
    return Mono.just("path value: " + path);
}
To reproduce...

Steps to reproduce the behavior:

  1. Go to the Swagger UI GET /example/{*path} endpoint and click Try it out
  2. Click in the path variable and enter foo/bar
  3. Click the Execute button
  4. Observe that all of the Curl, Request URL & Response body sections show the value {*path} instead of foo/bar
  5. Open a new browser tab
  6. Enter the following url (mody as needed for your project): http://localhost:8454/example/foo/bar
  7. Observe that the value foo/bar is shown as expected
Expected behavior

The value foo/bar should be shown in Swagger UI.

Screenshots

image
image

Additional context or thoughts

There is a workaround, of sorts. This workaround seems to point to a problem with the expected variable name.

But it's not 100% because Swagger UI insists on escaping the multiple segment path entered into the path variable, which is undesirable for this style of multiple segment path variable. See screenshots. I would expect it to be substituted verbatim without escaping in this scenario.

Though, in the end, this works because Spring unescapes the value for you, but it looks ugly in Swagger UI.

@GetMapping(path = "/{*path}", produces = MediaType.TEXT_PLAIN_VALUE)
public Mono<String> pathMatching(@Parameter(name = "*path") @PathVariable String path) {
    return Mono.just("path value: " + path);
}
Additional Screenshots

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the WebFlux example in Swagger UI with a GET path of /{*path} and the value foo/bar. Trace the UI's path-parameter substitution and request URL generation, then verify that the generated Curl, Request URL, and response use foo/bar rather than the literal {*path} while preserving the expected multi-segment behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.