-
Notifications
You must be signed in to change notification settings - Fork 6k
[Jaxrs] Add beanvalidation annotations and fix outer Enums #4492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a449613
add beanvalidation to jaxrs and add support for outer Enums #4091
jfiala f479b6b
cleanup Codegen #4091
jfiala 3b7d515
cleanup samples #4091
jfiala 119f693
cleanup tabs
jfiala daf433a
updated samples to petstore.yaml (before petstore.json)
jfiala 8622167
add support for DecimalMin/DecimalMax/Min/Max #4091
jfiala 01f3591
add check for hideGenerationTimestamp #4091
jfiala 763a719
replace tabs
jfiala 79e78e9
correct line endings to lf
jfiala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/beanValidation.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| {{#required}} | ||
| @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 / number=decimal type}} | ||
| {{#isInteger}} | ||
| {{#minimum}} | ||
| @Min({{minimum}}) | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| @Max({{maximum}}) | ||
| {{/maximum}} | ||
| {{/isInteger}} | ||
| {{^isInteger}} | ||
| {{#minimum}} | ||
| @DecimalMin("{{minimum}}") | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| @DecimalMax("{{maximum}}") | ||
| {{/maximum}} | ||
| {{/isInteger}} |
1 change: 1 addition & 0 deletions
1
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/beanValidationPathParams.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{! PathParam is always required, no @NotNull necessary }}{{#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}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} |
1 change: 1 addition & 0 deletions
1
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/beanValidationQueryParams.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#required}} @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}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}} |
37 changes: 26 additions & 11 deletions
37
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/enumClass.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,31 @@ | ||
| import javax.xml.bind.annotation.XmlEnum; | ||
| import javax.xml.bind.annotation.XmlType; | ||
| public enum {{datatypeWithEnum}} { | ||
|
|
||
| {{#allowableValues}} | ||
| {{#enumVars}}{{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; | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/enumOuterClass.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| {{#jackson}} | ||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
| {{/jackson}} | ||
|
|
||
| /** | ||
| * {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} | ||
| */ | ||
| public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { | ||
| {{#gson}} | ||
| {{#allowableValues}}{{#enumVars}} | ||
| @SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}) | ||
| {{{name}}}({{{value}}}){{^-last}}, | ||
| {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| {{/gson}} | ||
| {{^gson}} | ||
| {{#allowableValues}}{{#enumVars}} | ||
| {{{name}}}({{{value}}}){{^-last}}, | ||
| {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
| {{/gson}} | ||
|
|
||
| private {{{dataType}}} value; | ||
|
|
||
| {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| @Override | ||
| @JsonValue | ||
| public String toString() { | ||
| return String.valueOf(value); | ||
| } | ||
|
|
||
| @JsonCreator | ||
| public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue(String text) { | ||
| for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) { | ||
| if (String.valueOf(b.value).equals(text)) { | ||
| return b; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
4 changes: 2 additions & 2 deletions
4
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/formParams.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| {{#isFormParam}}{{#notFile}}@FormParam(value = "{{paramName}}"{{^required}}, required = false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} @FormParam(value = "{{paramName}}"{{^required}}, required = false{{/required}}) InputStream {{paramName}}InputStream, | ||
| @FormParam(value = "{{paramName}}" {{^required}}, required = false{{/required}}) Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}} | ||
| {{#isFormParam}}{{#notFile}}@FormParam(value = "{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}} @FormParam(value = "{{paramName}}") InputStream {{paramName}}InputStream, | ||
| @FormParam(value = "{{paramName}}") Attachment {{paramName}}Detail{{/isFile}}{{/isFormParam}} |
4 changes: 3 additions & 1 deletion
4
modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/generatedAnnotation.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| @javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") | ||
| {{^hideGenerationTimestamp}} | ||
| @javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}") | ||
| {{/hideGenerationTimestamp}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I suggest we keep
useBeanValidationto false similar to what we've done for other Java-related generator: https://github.com/swagger-api/swagger-codegen/search?l=Java&q=useBeanValidation&utf8=%E2%9C%93There 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.
same as #4506, please advise if the decision is to keep the default to false (current impl of cxf/java) or true (suggestion of @cbornet)?
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.
@jfiala I'll think about this more and get back to you.