Skip to content

Commit 030b75b

Browse files
JFCotewing328
andauthored
[Play Framework] Update the bean validation to use version 2.0. (#8354)
* Update the bean validation to use version 2.0. For a reason I don't know, it was not working anymore with version 1. * better format Co-authored-by: William Cheng <wing328hk@gmail.com>
1 parent 96da7aa commit 030b75b

117 files changed

Lines changed: 849 additions & 448 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/JavaPlayFramework/beanValidation.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@
5353
{{/isInteger}}
5454
{{^isPrimitiveType}}
5555
@Valid
56-
{{/isPrimitiveType}}
56+
{{/isPrimitiveType}}

modules/openapi-generator/src/main/resources/JavaPlayFramework/build.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ scalaVersion := "2.12.6"
1010
libraryDependencies += "org.webjars" % "swagger-ui" % "3.32.5"
1111
{{/useSwaggerUI}}
1212
{{#useBeanValidation}}
13-
libraryDependencies += "javax.validation" % "validation-api" % "1.1.0.Final"
13+
libraryDependencies += "javax.validation" % "validation-api" % "2.0.1.Final"
1414
{{/useBeanValidation}}
1515
libraryDependencies += guice

modules/openapi-generator/src/main/resources/JavaPlayFramework/pojo.mustache

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
2626
@SerializedName("{{baseName}}")
2727
{{/gson}}
2828
{{#isContainer}}
29+
{{#useBeanValidation}}
30+
{{>beanValidation}}
31+
{{/useBeanValidation}}
2932
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
3033
{{/isContainer}}
3134
{{^isContainer}}
35+
{{#useBeanValidation}}
36+
{{>beanValidation}}
37+
{{/useBeanValidation}}
3238
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
3339
{{/isContainer}}
3440

@@ -78,10 +84,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
7884
{{/maximum}}
7985
* @return {{name}}
8086
**/
81-
{{#vendorExtensions.x-extra-annotation}}
87+
{{#vendorExtensions.x-extra-annotation}}
8288
{{{vendorExtensions.x-extra-annotation}}}
8389
{{/vendorExtensions.x-extra-annotation}}
84-
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
90+
public {{{datatypeWithEnum}}} {{getter}}() {
8591
return {{name}};
8692
}
8793

samples/server/petstore/java-play-framework-api-package-override/app/apimodels/Category.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
1313
public class Category {
1414
@JsonProperty("id")
15+
1516
private Long id;
1617

1718
@JsonProperty("name")
19+
1820
private String name;
1921

2022
public Category id(Long id) {
@@ -26,7 +28,7 @@ public Category id(Long id) {
2628
* Get id
2729
* @return id
2830
**/
29-
public Long getId() {
31+
public Long getId() {
3032
return id;
3133
}
3234

@@ -43,7 +45,7 @@ public Category name(String name) {
4345
* Get name
4446
* @return name
4547
**/
46-
public String getName() {
48+
public String getName() {
4749
return name;
4850
}
4951

samples/server/petstore/java-play-framework-api-package-override/app/apimodels/ModelApiResponse.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
1313
public class ModelApiResponse {
1414
@JsonProperty("code")
15+
1516
private Integer code;
1617

1718
@JsonProperty("type")
19+
1820
private String type;
1921

2022
@JsonProperty("message")
23+
2124
private String message;
2225

2326
public ModelApiResponse code(Integer code) {
@@ -29,7 +32,7 @@ public ModelApiResponse code(Integer code) {
2932
* Get code
3033
* @return code
3134
**/
32-
public Integer getCode() {
35+
public Integer getCode() {
3336
return code;
3437
}
3538

@@ -46,7 +49,7 @@ public ModelApiResponse type(String type) {
4649
* Get type
4750
* @return type
4851
**/
49-
public String getType() {
52+
public String getType() {
5053
return type;
5154
}
5255

@@ -63,7 +66,7 @@ public ModelApiResponse message(String message) {
6366
* Get message
6467
* @return message
6568
**/
66-
public String getMessage() {
69+
public String getMessage() {
6770
return message;
6871
}
6972

samples/server/petstore/java-play-framework-api-package-override/app/apimodels/Order.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
1414
public class Order {
1515
@JsonProperty("id")
16+
1617
private Long id;
1718

1819
@JsonProperty("petId")
20+
1921
private Long petId;
2022

2123
@JsonProperty("quantity")
24+
2225
private Integer quantity;
2326

2427
@JsonProperty("shipDate")
28+
@Valid
29+
2530
private OffsetDateTime shipDate;
2631

2732
/**
@@ -58,9 +63,11 @@ public static StatusEnum fromValue(String value) {
5863
}
5964

6065
@JsonProperty("status")
66+
6167
private StatusEnum status;
6268

6369
@JsonProperty("complete")
70+
6471
private Boolean complete = false;
6572

6673
public Order id(Long id) {
@@ -72,7 +79,7 @@ public Order id(Long id) {
7279
* Get id
7380
* @return id
7481
**/
75-
public Long getId() {
82+
public Long getId() {
7683
return id;
7784
}
7885

@@ -89,7 +96,7 @@ public Order petId(Long petId) {
8996
* Get petId
9097
* @return petId
9198
**/
92-
public Long getPetId() {
99+
public Long getPetId() {
93100
return petId;
94101
}
95102

@@ -106,7 +113,7 @@ public Order quantity(Integer quantity) {
106113
* Get quantity
107114
* @return quantity
108115
**/
109-
public Integer getQuantity() {
116+
public Integer getQuantity() {
110117
return quantity;
111118
}
112119

@@ -123,7 +130,6 @@ public Order shipDate(OffsetDateTime shipDate) {
123130
* Get shipDate
124131
* @return shipDate
125132
**/
126-
@Valid
127133
public OffsetDateTime getShipDate() {
128134
return shipDate;
129135
}
@@ -141,7 +147,7 @@ public Order status(StatusEnum status) {
141147
* Order Status
142148
* @return status
143149
**/
144-
public StatusEnum getStatus() {
150+
public StatusEnum getStatus() {
145151
return status;
146152
}
147153

@@ -158,7 +164,7 @@ public Order complete(Boolean complete) {
158164
* Get complete
159165
* @return complete
160166
**/
161-
public Boolean getComplete() {
167+
public Boolean getComplete() {
162168
return complete;
163169
}
164170

samples/server/petstore/java-play-framework-api-package-override/app/apimodels/Pet.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,27 @@
1616
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
1717
public class Pet {
1818
@JsonProperty("id")
19+
1920
private Long id;
2021

2122
@JsonProperty("category")
23+
@Valid
24+
2225
private Category category;
2326

2427
@JsonProperty("name")
28+
@NotNull
29+
2530
private String name;
2631

2732
@JsonProperty("photoUrls")
33+
@NotNull
34+
2835
private List<String> photoUrls = new ArrayList<>();
2936

3037
@JsonProperty("tags")
38+
@Valid
39+
3140
private List<Tag> tags = null;
3241

3342
/**
@@ -64,6 +73,7 @@ public static StatusEnum fromValue(String value) {
6473
}
6574

6675
@JsonProperty("status")
76+
6777
private StatusEnum status;
6878

6979
public Pet id(Long id) {
@@ -75,7 +85,7 @@ public Pet id(Long id) {
7585
* Get id
7686
* @return id
7787
**/
78-
public Long getId() {
88+
public Long getId() {
7989
return id;
8090
}
8191

@@ -92,7 +102,6 @@ public Pet category(Category category) {
92102
* Get category
93103
* @return category
94104
**/
95-
@Valid
96105
public Category getCategory() {
97106
return category;
98107
}
@@ -110,7 +119,6 @@ public Pet name(String name) {
110119
* Get name
111120
* @return name
112121
**/
113-
@NotNull
114122
public String getName() {
115123
return name;
116124
}
@@ -133,7 +141,6 @@ public Pet addPhotoUrlsItem(String photoUrlsItem) {
133141
* Get photoUrls
134142
* @return photoUrls
135143
**/
136-
@NotNull
137144
public List<String> getPhotoUrls() {
138145
return photoUrls;
139146
}
@@ -159,7 +166,6 @@ public Pet addTagsItem(Tag tagsItem) {
159166
* Get tags
160167
* @return tags
161168
**/
162-
@Valid
163169
public List<Tag> getTags() {
164170
return tags;
165171
}
@@ -177,7 +183,7 @@ public Pet status(StatusEnum status) {
177183
* pet status in the store
178184
* @return status
179185
**/
180-
public StatusEnum getStatus() {
186+
public StatusEnum getStatus() {
181187
return status;
182188
}
183189

samples/server/petstore/java-play-framework-api-package-override/app/apimodels/Tag.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
@SuppressWarnings({"UnusedReturnValue", "WeakerAccess"})
1313
public class Tag {
1414
@JsonProperty("id")
15+
1516
private Long id;
1617

1718
@JsonProperty("name")
19+
1820
private String name;
1921

2022
public Tag id(Long id) {
@@ -26,7 +28,7 @@ public Tag id(Long id) {
2628
* Get id
2729
* @return id
2830
**/
29-
public Long getId() {
31+
public Long getId() {
3032
return id;
3133
}
3234

@@ -43,7 +45,7 @@ public Tag name(String name) {
4345
* Get name
4446
* @return name
4547
**/
46-
public String getName() {
48+
public String getName() {
4749
return name;
4850
}
4951

0 commit comments

Comments
 (0)