I use this library for generation documentation:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.0</version>
</dependency>
I have this controller:
@RestController
public class TestController {
@GetMapping("/test{hz}")
public String test(@PathVariable(value = "hz", required = false) String hz) {
return "test";
}
}
But I get this documentation:
Why required = false
doesn't work?
I tried this:
@RestController
public class TestController {
@GetMapping("/test{hz}")
public String test(
@Parameter(description = "foo", required = false)
@PathVariable(value = "hz", required = false) String hz) {
return "test";
}
}
It doesn't work too
EDIT: (Answer for @Helen comment) - Of course I know about this:
@RestController
public class TestController {
@GetMapping(value = {"/test", "/test{hz}"})
public String test(
@Parameter(description = "foo", required = false)
@PathVariable(value = "hz", required = false) String hz) {
return "test";
}
}
And I tried this:
@PathVariable(value = "hz", required = false) Optional<String> hz
It makes documentation worse. so I didn't add this code. With {"/test", "/test{hz}"}
It looks like this: