Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PathVariable as optional in swagger SpringFox(3.0.0)

I have upgraded to the latest version of SpringFox(3.0.0) recently.
PathVariable marked as required = false is showing as mandatory.

Below is my controller method code

@GetMapping(path = { "/persons", "/persons/{id} })
public List<Person> getPerson(@PathVariable(required = false) String id) {
    
}

I have tried adding @ApiParam, by default it is false. But still, on swagger it is showing as mandatory.

Previously with SpringFox(2.9.0) it was working fine, on swagger it was marked as optional

Any help in this will be appreciated.
Thank you

like image 985
SSK Avatar asked May 25 '26 16:05

SSK


1 Answers

Path parameters are always required. If we are having an optional path variable then we need to define the two separate end poinds.

I have added two endpoints to solve my problem as shown below.

@GetMapping(path = { "/persons })
public List<Person> getAllPerson() {
    
}

@GetMapping(path = {"/persons/{id} })
public List<Person> getPersonById(@PathVariable String id) {
    
}
like image 65
SSK Avatar answered May 27 '26 05:05

SSK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!