4

I want to create swagger documentation for an endpoint with ** pattern. In swagger-ui page I find the endpoint but there isn't any input for url of **. My endpoint signature is:

@GetMapping("/{category}/**")
public DocumentModel fetch(HttpServletRequest httpServletRequest, @PathVariable("category") String category)

I want to call above endpoint by myCategory/test/document1 address but there isn't any placeholder for test/document1. How can I call this endpoint by swagger?

1 Answer 1

0

Unfortunately, it is not doable. Swagger supports neither wildcards in the path, nor optional path segments, nor slashes in path parameter values. If you look at the request that swagger-ui executes for your mapping, you will see something like this:

curl -X GET "http://localhost:8080/category1/**"

The stars are not replaced, they are treated as a normal string, not as a placeholder.

I am afraid your only option is modifying the endpoint or adding a new one, e.g:

@GetMapping("/{category}/test/{document}")
@Parameter(name = "document", in = ParameterIn.PATH)
public DocumentModel fetchTest(HttpServletRequest httpServletRequest, @PathVariable("category") String category) {
    return fetch(httpServletRequest, category);
}

@GetMapping("/{category}/**")
public DocumentModel fetch(HttpServletRequest httpServletRequest, @PathVariable("category") String category) {
    // ...
}

If you need to, you can hide the original endpoint from the swagger-ui:

@GetMapping("/{category}/**")
@Operation(hidden = true)
public DocumentModel fetch(HttpServletRequest httpServletRequest, @PathVariable("category") String category) {
    // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.