-
Notifications
You must be signed in to change notification settings - Fork 6k
[Jaxrs-cxf-cdi] Add beanvalidation annotations updated #4615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
00664bc
7df73e3
9f01c58
14bb432
04b1df0
2f42133
d08661a
7c29f9e
84e3a80
59caedd
4cc5b0b
bff8231
7ab67ae
98b657d
35e0c0e
4b301f7
df67581
f8487aa
c3669c4
9b4c327
66156fc
c87e93f
cab2cbe
9941dea
e755583
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| {{#required}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can beanValidation.mustache also bring in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the difference here is that in beanValidation.mustache every annotation gets a new line whereas in the params template all annotation share the same line. So I fear we have to keep them separate.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK - because this template is used for method annotations, you're adding newlines. However, to my knowledge, there's no Java syntax requirement for newlines on method/property annotations - indeed, much like parameter annotations, newlines are about style, rather than syntax. So - syntactically I think this would be OK without the newlines. What do you think? I've also noticed you've got some clever integer/decimal handling in here that's missing in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if its better to drop the newlines in favor of having one beanValidationCore.mustache. From a beauty of generated code perspective I'd favor the current solution at the cost of having to maintain both. We could add a mustache comment to remind the maintainers. In fact the bigger effort is having to maintain beanValidation*.mustache across all Java languages, but that's a different story... |
||
| @NotNull | ||
| {{/required}} | ||
| {{#pattern}} | ||
| @Pattern(regexp="{{pattern}}") | ||
| {{/pattern}} | ||
| {{#minLength}} | ||
| {{#maxLength}} | ||
| @Size(min={{minLength}},max={{maxLength}}) | ||
| {{/maxLength}} | ||
| {{/minLength}} | ||
| {{#minLength}} | ||
| {{^maxLength}} | ||
| @Size(min={{minLength}}) | ||
| {{/maxLength}} | ||
| {{/minLength}} | ||
| {{^minLength}} | ||
| {{#maxLength}} | ||
| @Size(max={{maxLength}}) | ||
| {{/maxLength}} | ||
| {{/minLength}} | ||
| {{#minItems}} | ||
| {{#maxItems}} | ||
| @Size(min={{minItems}},max={{maxItems}}) | ||
| {{/maxItems}} | ||
| {{/minItems}} | ||
| {{#minItems}} | ||
| {{^maxItems}} | ||
| @Size(min={{minItems}}) | ||
| {{/maxItems}} | ||
| {{/minItems}} | ||
| {{^minItems}} | ||
| {{#maxItems}} | ||
| @Size(max={{maxItems}}) | ||
| {{/maxItems}} | ||
| {{/minItems}} | ||
| {{! check for integer or long / all others=decimal type with @Decimal*}} | ||
| {{#isInteger}} | ||
| {{#minimum}} | ||
| @Min({{minimum}}) | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| @Max({{maximum}}) | ||
| {{/maximum}} | ||
| {{/isInteger}} | ||
| {{#isLong}} | ||
| {{#minimum}} | ||
| @Min({{minimum}}) | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| @Max({{maximum}}) | ||
| {{/maximum}} | ||
| {{/isLong}} | ||
| {{^isInteger}} | ||
| {{^isLong}} | ||
| {{#minimum}} | ||
| @DecimalMin("{{minimum}}") | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| @DecimalMax("{{maximum}}") | ||
| {{/maximum}} | ||
| {{/isLong}} | ||
| {{/isInteger}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| {{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{! | ||
| check for integer or long / all others=decimal type with @Decimal* | ||
| }}{{#isInteger}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/isInteger}}{{#isLong}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}{{/isLong}}{{^isInteger}}{{^isLong}}{{#minimum}} @DecimalMin("{{minimum}}"){{/minimum}}{{#maximum}} @DecimalMax("{{maximum}}"){{/maximum}}{{/isLong}}{{/isInteger}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{! PathParam is always required, no @NotNull necessary }}{{>beanValidationParams}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#required}} @NotNull{{/required}}{{>beanValidationParams}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,33 @@ | ||
| import javax.xml.bind.annotation.XmlEnum; | ||
| import javax.xml.bind.annotation.XmlType; | ||
| @XmlType(name="{{datatypeWithEnum}}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have enum changes in here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nickcmaynard With the old version enumClass.mustache there are compile errors, as the generated sample files were out of date. Pls simply try with the old version and then you see the compilation errors.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point is that this is a simple case of one PR, two issues. We should get into the habit of one PR, one issue.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm absolutely with you (if the samples are up to date and compiling). |
||
| @XmlEnum({{datatype}}.class) | ||
| public enum {{datatypeWithEnum}} { | ||
|
|
||
| {{#allowableValues}} | ||
| {{#enumVars}}@XmlEnumValue({{{value}}}) {{name}}({{datatype}}.valueOf({{{value}}})){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}} | ||
| {{/allowableValues}} | ||
|
|
||
|
|
||
| private {{datatype}} value; | ||
|
|
||
| {{datatypeWithEnum}} ({{datatype}} v) { | ||
| value = v; | ||
| } | ||
|
|
||
| @XmlType(name="{{classname}}") | ||
| @XmlEnum | ||
| public enum {{classname}} { | ||
| {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/allowableValues}} | ||
|
|
||
| public String value() { | ||
| return name(); | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.valueOf(value); | ||
| } | ||
|
|
||
| public static {{classname}} fromValue(String v) { | ||
| return valueOf(v); | ||
| public static {{datatypeWithEnum}} fromValue(String v) { | ||
| for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { | ||
| if (String.valueOf(b.value).equals(v)) { | ||
| return b; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| @javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") | ||
| {{^hideGenerationTimestamp}}@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}} | ||
| {{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,16 @@ | |
| <artifactId>swagger-annotations</artifactId> | ||
| <version>[1.5.3,2)</version> | ||
| </dependency> | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section incorrectly indented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you probably mean the beanvalidation dependency, this is fixed now. |
||
| {{#useBeanValidation}} | ||
| <!-- Bean Validation API support --> | ||
| <dependency> | ||
| <groupId>javax.validation</groupId> | ||
| <artifactId>validation-api</artifactId> | ||
| <version>1.1.0.Final</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| {{/useBeanValidation}} | ||
|
|
||
| </dependencies> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{#defaultValue}}@DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}} | ||
| {{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{#defaultValue}}@DefaultValue("{{{defaultValue}}}"){{/defaultValue}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This,
beanValidationPathParams.mustache, andbeanValidationQueryParams.mustacheare very similar. I understand the arguments for avoiding reuse across language generators, but I simply don't agree that needs to be the case within a language generator. I think these three files need refactoring to remove the duplication.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the only difference is that PathParams are always required, so they don't need a check for NotNull, I commented this in beanValidationPathParams.mustache. So we could extract all other annotation checks into a beanValidationCommonParams.mustache.
Regarding cross-language templates using lambdas this is a nice feature of Mustache, but we need green light from @fehguy /@wing328 for cross-language template reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, within the language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for the hint, the templates are now reused in beanValidationParams.mustache.