When useBeanValidation flag is true, it does not add @Valid annotation to attributes of type object. For instance, I have the class JoinDetails which has a field of type MemberProfile. When I validate joinDetails instance, the validator does not validate memberProfile because there is no @Valid annotation on it. It would be better if swagger-codegen can support this use cases either using extraAnnotation (i.e. x-extraAnnotation: "@Valid") in swagger config or automatically added during code generation.
2.2.2-SNAPSHOT
```yaml
JoinDetails:
type: object
required:
- memberProfile
properties:
memberProfile:
$ref: '#/definitions/MemberProfile'
MemberProfile:
type: object
required:
- firstName
- lastName
properties:
firstName:
type: string
maxLength: 50
lastName:
type: string
maxLength: 50
```
I'm using maven:
Add support via x- extension or automatically detect complex object or entities from the model.
@jmiddleton thanks for the suggestion. For this particular case, I think @Valid should be added automatically.
cc @jfiala
There are two different use-cases for @Valid:
1.) Cascaded bean validation:
https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-bean-constraints.html#example-cascaded-validation
This is the topic of the current issue.
2.) Cascaded method-level bean validation:
https://docs.jboss.org/hibernate/validator/5.1/reference/en-US/html/chapter-method-constraints.html#chapter-method-constraints
This is described in #4847 (including PR for Spring)
Overview of all the languages to be updated:
This also applies to jaxrs (Jersey2). I could provide a patch.
Is someone already working on the same issue for jaxrs-cxf? @michaelpaesold are you still working on a patch for jaxrs?
@olivierpaquet I did the PR in summer last year as you already seem to have discovered. But currently I'm not working on it, so feel free to catch up and get it pulled in...
@olivierpaquet I have rebased @jfiala 's changes on the current master. I will check now how to ensure that the Valid-annotation is only applied to types which are generated by the model (the problem mentioned in https://github.com/swagger-api/swagger-codegen/pull/4922).
When ready I'll submit a new pull-request.
See https://github.com/fabian-braun/swagger-codegen/commits/cxf_beanval_valid_pojo
@jfiala , would you do the review or maybe point me to someone else I could ask? If I can further support with anything let me know
@fabian-braun Sorry I'm totally occupied with other things, maybe @cbornet can take a look in the meanwhile?