Issue
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. src="https://i.stack.imgur.com/kOT7k.png" alt="enter image description here" />
Solution
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);
}
Answered By - Milad Amery
Answer Checked By - Mary Flores (JavaFixing Volunteer)