swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Provide documentation for RequiredMode

Open spartanhooah opened this issue 2 years ago • 1 comments

I am updating a project from Swagger v2. I found that the required attribute of @Schema is deprecated, and requiredMode should be used instead. The default value of requiredMode is AUTO, but the javadocs don't explain what that means. Please update the documentation.

spartanhooah avatar Sep 26 '23 12:09 spartanhooah

If the requiredMode parameter is set to AUTO, swagger will check upstream whether your field is marked with @NotBlank or @NotNull or ... to set the requiredMode to REQUIRED or NOT_REQUIRED otherwise.

For example :

public class Test{
    @JsonProperty("property")
    @Schema(description = "My property")
    private String property; //this field will be NOT_REQUIRED because it's not marked as @NotBlank or @NotNull or ...

    @NotBlank
    @JsonProperty("property_2")
    @Schema(description = "My property_2")
    private String property2; //this field is REQUIRED as it is marked as @NotBlank 
}

sinclairjaza avatar Feb 13 '24 16:02 sinclairjaza