BeanValidation support has been added in #4003 for Java and jaxrs-cxf/jaxrs-cxf-client.
This needs to be added to all other Java languages
PR Beanvalidation annotation for Java and CXF #4003
Issues with language jaxrs-spec #4509
Update: moved all the issues with jaxrs-spec to #4509
Also add support for @DecimalMin/@DecimalMax
Final Cleanup implemented in PR #4635
@wing328 If you like I can cycle through the language templates and add (optional) beanvalidation support there. Or do you prefer the language maintainers to do the job?
@jfiala if you've time, please add the bean validation support. I'm sure the community and the template owner would appreciate your effort.
Small remark: if bean validation is an option, it should be activated by default (since you expect the generated code to follow the contract established by the swagger spec)
@jfiala
We would like to get support for server side code generation for jaxrs ( jersey2) with JSR303 annotations. We are doing topdown approach of writing apis in swagger editor and generating the code. I would really appreciate if you prioritize the JSR303 addition to server code for jaxrs ( jersey2). Will it add support for custom annotation also ? Thanks.
@deveshpujari @wing328 added beanvalidation support to jaxrs-spec, I also had to fix an issue with outer Enums. BeanValidation annotations are now active by default and can be turned off using the CLI parameter useBeanValidation.
Additional issues with jaxrs-spec:
I suggest fixing those in a separate issue for jaxrs-spec.
@deveshpujari @wing328 added beanvalidation support to jaxrs (jersey2) and library jersey1, please take a look.
Issues with jaxrs (=Jersey)
- name: number
type: number
maximum: 543.2
minimum: 32.1
For type number, the annotations should probably be @DecimalMin/@DecimalMax
@DecimalMin/@DecimalMax are for BigDecimal only, so IMHO we need to distinguish between integer and decimal datatypes to generate the correct annotations. Is there already a flag for to do this already available in the mustache templates?
Type number is mapped to BigDecimal.
If you talk about Float/Double formats, I don't know if @Min/Max or @DecimalXXX can be used. It probably depends on the validation framework used. So you should probably not use format: float with min and max in your swagger spec...
And I think @DecimalXXX works with Integer, Long, etc ...
@DecimalMin/DecimalMax is reserved for decimal values:
https://docs.oracle.com/cd/E19798-01/821-1841/gircz/index.html
"The value of the field or property must be a decimal value lower than or equal to the number in the value element. "
@Min/@Max are for integer values:
"The value of the field or property must be an integer value lower than or equal to the number in the value element. "
http://swagger.io/specification/
type=number => @DecimalMin/DecimalMax
type=integer => @Min/@Max
I added checks for isInteger/^isInteger and now we support @Min/@Max/@DecimalMin/@DecimalMax, thx for the hint.
That's not what I read here : http://docs.oracle.com/javaee/6/api/javax/validation/constraints/DecimalMin.html
A quick test should answer that 馃槃
Hm - Using @Min/@Max for integers appears cleaner to me, as @DecimalMin/@DecimalMax use a string for the limit.
@jfiala agreed
You probably also want @Min/@Max for isLong
common name integer/long = type integer => isInteger should include both format32 (integer) and format64 (long) (see http://swagger.io/specification/).
changed in jaxrs/jaxrs-spec and jaxrs-resteasy
common name integer/long = type integer => isInteger should include both format32 (integer) and format64 (long) (see http://swagger.io/specification/).
Looking at the code, it doesn't seem to be the case...
you're right, should I add support for isLong or we can we better add isTypeInteger (which could then correctly include integer + long)?
So far added beanvalidation annotation support to all Java languages listed at the top.
Pls advise regarding isInteger/isLong vs isTypeInteger then I can backport this to cxf/java as well.
Java beanvalidation has been fully implemented, further enhancements for @Valid are dealt with separate issues.
Most helpful comment
@jfiala
We would like to get support for server side code generation for jaxrs ( jersey2) with JSR303 annotations. We are doing topdown approach of writing apis in swagger editor and generating the code. I would really appreciate if you prioritize the JSR303 addition to server code for jaxrs ( jersey2). Will it add support for custom annotation also ? Thanks.