question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@ApiModelProperty required=false is overriden by @NotNull annotation

See original GitHub issue

Please 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
m-radzikowskicommented, Dec 26, 2016

Well, it’s weird that external (@NotNull) annotation has priority over library’s own annotation (@ApiModelProperty) when it comes to displaying library-specific stuff…

0reactions
kimjunycommented, Jun 27, 2019

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 notNullGroups inside ApiModelProperty, but again, that would be waste since the NotNull validator has already declared the group.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found