@ApiModelProperty required=false is overriden by @NotNull annotation
See original GitHub issuePlease consider this example:
@ApiModelProperty(required = false, value = "Required only for Ipsum group")
@NotNull(groups = Ipsum.class)
private int lorem;
In this case we have @NotNull annotation, but with specified validation group. Because of that in swagger this property shouldn’t be marked as required so we add required=false in @ApiModelProperty. Unfortunately @NotNull annotation seems to have priority over Swagger own @ApiModelProperty and lorem is still marked as required.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Optional ApiModelProperty appearing in JSON Swagger ...
Solved, I just had to add this Jackson annotation for the given field : @JsonInclude(JsonInclude.Include.
Read more >ApiModelProperty (swagger-annotations 1.5.12 API)
Specifies if the parameter is required or not. Default: false. position. public abstract int position. Allows explicitly ordering the property in the model....
Read more >JSON Serializaton update behaviour error - Camunda forum
I have configured my Camumda instance to use JSON serialization via the: /server/apache-tomcat-9.0.52/conf/bpm-platform.xml. Adding:
Read more >javax.validation.constraints.NotNull.<init> java code examples
NotNull @Size(min = 1) ... @ApiModelProperty(value = "手机号", example = "18888888888", required = true) private String mobile; @NotNull @Size(min = 6, ...
Read more >Model Mapping · ScrudBeans - Manos Batsis
null, @field:NotNull @field:Column(nullable = false) @field:Schema(title = "The client's ... The @ScrudBean annotation marks the entity model for annotation ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Well, it’s weird that external (
@NotNull) annotation has priority over library’s own annotation (@ApiModelProperty) when it comes to displaying library-specific stuff…This is a reasonable request, because we want the api model itself to be reusable when dealing with different type of input situation. I think a feasible solution could be something like
notNullGroupsinsideApiModelProperty, but again, that would be waste since theNotNullvalidator has already declared the group.