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.

Conditional @Validated annotation is ignored

See original GitHub issue

What 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:open
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
MaksimOrlovcommented, May 14, 2020

@AliAkbarMoeini, release is planned to this month. That is link for details

3reactions
MaksimOrlovcommented, Mar 19, 2018

Approximately it will take a few months to be present in the snapshot version.

Read more comments on GitHub >

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

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