Skip to content

Commit ce930e7

Browse files
fabian-braunwing328
authored andcommitted
[Jaxrs-cxf] Add bean-level cascaded beanvalidation for pojos (@Valid) fix #4738 (#7807)
* add valid for pojos #4738 * add Valid to imports for pojos #4738 * Do not generate Valid-annotation for Date-types and UUID * * add Valid-annotation to Containers. #4738 Collection-valued, array-valued and generally Iterable fields and properties may also be decorated with the @Valid annotation. This causes the contents of the iterator to be validated. Quoted from: http://beanvalidation.org/1.1/spec/ * add equivalent windows-bat-script for jaxrs-cxf-petstore-server.sh * differences on jaxrs-cxf-generated-classes introduced by other changes (not related to this PR)
1 parent d2bd41d commit ce930e7

39 files changed

+128
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
8+
set ags=generate -t modules\swagger-codegen\src\main\resources\JavaJaxRS\cxf -i modules\swagger-codegen\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -l jaxrs-cxf -o samples\server\petstore\jaxrs-cxf -DhideGenerationTimestamp=true
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package {{package}};
44
{{/imports}}
55
{{#useBeanValidation}}
66
import javax.validation.constraints.*;
7+
import javax.validation.Valid;
78
{{/useBeanValidation}}
89

910
{{#models}}

modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
3131
{{#withXml}}
3232
@XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}})
3333
{{/withXml}}
34-
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
34+
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}"){{^isPrimitiveType}}{{^isDate}}{{^isDateTime}}{{^isString}}{{^isFile}}{{#useBeanValidation}}
35+
@Valid{{/useBeanValidation}}{{/isFile}}{{/isString}}{{/isDateTime}}{{/isDate}}{{/isPrimitiveType}}
3536
{{#description}}
3637
/**
37-
* {{{description}}}
38+
* {{{description}}}
3839
**/
3940
{{/description}}
4041
{{#isContainer}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.4.0-SNAPSHOT

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/api/FakeClassnameTags123Api.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
public interface FakeClassnameTags123Api {
3131

3232
/**
33+
* To test class name in snake case
34+
*
3335
* To test class name in snake case
3436
*
3537
*/

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/api/StoreApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public interface StoreApi {
7373
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
7474
@ApiResponse(code = 400, message = "Invalid ID supplied"),
7575
@ApiResponse(code = 404, message = "Order not found") })
76-
public Order getOrderById(@PathParam("order_id") @Min(1) @Max(5) Long orderId);
76+
public Order getOrderById(@PathParam("order_id") @Min(1L) @Max(5L) Long orderId);
7777

7878
/**
7979
* Place an order for a pet

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/model/AdditionalPropertiesClass.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Map;
66
import javax.validation.constraints.*;
7+
import javax.validation.Valid;
78

89
import io.swagger.annotations.ApiModelProperty;
910
import javax.xml.bind.annotation.XmlElement;
@@ -21,6 +22,7 @@ public class AdditionalPropertiesClass {
2122
private Map<String, String> mapProperty = null;
2223

2324
@ApiModelProperty(value = "")
25+
@Valid
2426
private Map<String, Map<String, String>> mapOfMapProperty = null;
2527
/**
2628
* Get mapProperty

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/model/Animal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonSubTypes;
44
import com.fasterxml.jackson.annotation.JsonTypeInfo;
55
import javax.validation.constraints.*;
6+
import javax.validation.Valid;
67

78
import io.swagger.annotations.ApiModelProperty;
89
import javax.xml.bind.annotation.XmlElement;

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/model/AnimalFarm.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import javax.validation.constraints.*;
7+
import javax.validation.Valid;
78

89
import io.swagger.annotations.ApiModelProperty;
910
import javax.xml.bind.annotation.XmlElement;

samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/model/ArrayOfArrayOfNumberOnly.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import javax.validation.constraints.*;
7+
import javax.validation.Valid;
78

89
import io.swagger.annotations.ApiModelProperty;
910
import javax.xml.bind.annotation.XmlElement;
@@ -18,6 +19,7 @@
1819
public class ArrayOfArrayOfNumberOnly {
1920

2021
@ApiModelProperty(value = "")
22+
@Valid
2123
private List<List<BigDecimal>> arrayArrayNumber = null;
2224
/**
2325
* Get arrayArrayNumber

0 commit comments

Comments
 (0)