SpringDoc OpenAPI UI set default path parameter value

I have API and using Springdoc for api docs. There are several Controller classes, all of them having a class level /api/{apiVersion:^v[1-2]} mapping, however the apiVersion is not used in every method.

They look something like this:

@RestController
@RequestMapping("/api/{apiVersion:^v[1-2]}")
public class MyController1 {
    ...
    @GetMapping("/getSomething")
    public String getSomething(@PathVariable("apiVersion") String apiVersion) {
        if (apiVersion.equals("v1")) {
            ...
        } else {
            ...
        }
    }
}
@RestController
@RequestMapping("/api/{apiVersion:^v[1-2]}")
public class MyController2 {
    ...
    @GetMapping("/getOtherThing")
    public String getOtherThing() {
        ...
    }
}

The issue is that when I submit a request using the Try it out button, I can set the apiVersion parameter for the /getSomething endpoint but not for the /getOtherThing one, it will send {apiVersion}.

My question is if there is any way to make the Swagger UI to use a default value for the apiVersion path parameter when sending the request to the backend?

Leave a Comment