Conditional @Validated annotation is ignored
See original GitHub issueWhat kind of issue is this?
- @Validated annotation from org.springframework.validation.annotation is ignored by the doc generation of swagger.
- I’m using the springfox-bean-validators plugin to get @NotNull annotation constraints up in swagger documentation. However, those annotations from JSR-303 do work in conjunction with @Validated annotation from org.springframework.validation.annotation package to apply conditional validation constraints on the same model e.g.
In Model class (Entity.java):
@NotNull(message = "Field cannot be null", groups = {ConditionalValidation.class})
private String someField;
In Controller class:
public void createEntity( @Validated(ConditionalValidation.class) @RequestBody Entity someEntity) {}
- As of now, someField is always showing as required in the swagger documentation no matter if the conditional group is applied or not.
- I want to see in Swagger someField as required but only for the API createEntity and as optional for any other API that does apply the @Validate without the ConditionalValidation.class.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to conditionally invoke spring validators - Stack Overflow
There's two ways to do this. You can either. create a custom validation annotation and validator which checks the value of method and...
Read more >Spring Validation Example - Spring MVC Form Validator
We will use annotation based form validation and create our own custom validator based on JSR-303 specs standards.
Read more >Chapter 5. Grouping constraints - Red Hat on GitHub
The class Person in Example 5.1, “Person” has a @NotNull constraint on name. Since no group is specified for this annotation the default...
Read more >Are You Using @Valid and @Validated Annotations Wrong?
@Validated annotation must again be applied on the class level and to tell Spring which validation group should take effect, it must also...
Read more >Bean Validation: Practical Examples from a Real- World Java ...
Bean Validation annotations and demonstrates some practical techniques for ... Bean Validation API Hibernate Validator adds some useful constraints to those.
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
@AliAkbarMoeini, release is planned to this month. That is link for details
Approximately it will take a few months to be present in the snapshot version.