Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
my project is java spring boot 2 with maven . I use springdoc-openapi-ui dependency. problem is
@Parameter(required = false) not working on my api params.
–
–
–
I don't know how much of swagger annotations Springdoc-openapi supports but according to its own example at
PetApiDemo
in
/findByStatus
or
/findByTags
endpoints you can see by applying
@RequestParam(required = false)
which is a Spring Annotation! a parameter has become optional.
import org.springframework.web.bind.annotation.RequestParam;
default ResponseEntity<List<Pet>> findPetsByStatus(
@Parameter(
explode = Explode.TRUE,
name = "status",
in = ParameterIn.QUERY,
description = "Status values that need to be considered for filter",
style = ParameterStyle.FORM,
schema = @Schema(
type = "string", defaultValue = "available",
allowableValues = {"available", "pending", "sold"}
@Valid @RequestParam(value = "status", required = false)
List<String> status) {
return getDelegate().findPetsByStatus(status);
I had the same problem. My solution is add jakarta.annotation.@Nullable for non required parameters.
public ResponseEntity<?> getAllByMonthAndYear(
@Nullable @RequestParam("month") Integer month,
@Nullable @RequestParam("year") Integer year
) {...
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.