Skip to content

Commit 0aec772

Browse files
Zomzogwing328
authored andcommitted
[Java][jaxrs-resteasy] add @Valid when bean validation is enabled (#1237)
1 parent 258de89 commit 0aec772

File tree

19 files changed

+54
-37
lines changed

19 files changed

+54
-37
lines changed

modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import javax.inject.Inject;
2323

2424
{{#useBeanValidation}}
2525
import javax.validation.constraints.*;
26+
import javax.validation.Valid;
2627
{{/useBeanValidation}}
2728
{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2829
{{/isMultipart}}{{/operation}}{{/operations}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
1+
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#useBeanValidation}}{{#required}} @NotNull{{/required}} @Valid{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isBodyParam}}

modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/eap/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import javax.ws.rs.core.SecurityContext;
1919
import javax.ws.rs.*;
2020
{{#useBeanValidation}}
2121
import javax.validation.constraints.*;
22+
import javax.validation.Valid;
2223
{{/useBeanValidation}}
2324
{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2425
{{/isMultipart}}{{/operation}}{{/operations}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
1+
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, {{> allowableValues }}{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}){{#useBeanValidation}}{{#required}} @NotNull{{/required}} @Valid{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isBodyParam}}

samples/server/petstore/jaxrs-resteasy/default/src/gen/java/org/openapitools/api/PetApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.inject.Inject;
2424

2525
import javax.validation.constraints.*;
26+
import javax.validation.Valid;
2627
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2728

2829
@Path("/pet")
@@ -46,7 +47,7 @@ public class PetApi {
4647
}, tags={ "pet", })
4748
@io.swagger.annotations.ApiResponses(value = {
4849
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
49-
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext)
50+
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext)
5051
throws NotFoundException {
5152
return service.addPet(pet,securityContext);
5253
}
@@ -135,7 +136,7 @@ public Response getPetById( @PathParam("petId") Long petId,@Context SecurityCont
135136
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class),
136137

137138
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
138-
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext)
139+
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext)
139140
throws NotFoundException {
140141
return service.updatePet(pet,securityContext);
141142
}

samples/server/petstore/jaxrs-resteasy/default/src/gen/java/org/openapitools/api/StoreApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.inject.Inject;
2323

2424
import javax.validation.constraints.*;
25+
import javax.validation.Valid;
2526

2627
@Path("/store")
2728

@@ -82,7 +83,7 @@ public Response getOrderById( @Min(1L) @Max(5L) @PathParam("orderId") Long order
8283
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Order.class),
8384

8485
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid Order", response = Void.class) })
85-
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) Order order,@Context SecurityContext securityContext)
86+
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) @NotNull @Valid Order order,@Context SecurityContext securityContext)
8687
throws NotFoundException {
8788
return service.placeOrder(order,securityContext);
8889
}

samples/server/petstore/jaxrs-resteasy/default/src/gen/java/org/openapitools/api/UserApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.inject.Inject;
2323

2424
import javax.validation.constraints.*;
25+
import javax.validation.Valid;
2526

2627
@Path("/user")
2728

@@ -39,7 +40,7 @@ public class UserApi {
3940
@io.swagger.annotations.ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })
4041
@io.swagger.annotations.ApiResponses(value = {
4142
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
42-
public Response createUser(@ApiParam(value = "Created user object" ,required=true) User user,@Context SecurityContext securityContext)
43+
public Response createUser(@ApiParam(value = "Created user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext)
4344
throws NotFoundException {
4445
return service.createUser(user,securityContext);
4546
}
@@ -50,7 +51,7 @@ public Response createUser(@ApiParam(value = "Created user object" ,required=tru
5051
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
5152
@io.swagger.annotations.ApiResponses(value = {
5253
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
53-
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext)
54+
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext)
5455
throws NotFoundException {
5556
return service.createUsersWithArrayInput(user,securityContext);
5657
}
@@ -61,7 +62,7 @@ public Response createUsersWithArrayInput(@ApiParam(value = "List of user object
6162
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
6263
@io.swagger.annotations.ApiResponses(value = {
6364
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
64-
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext)
65+
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext)
6566
throws NotFoundException {
6667
return service.createUsersWithListInput(user,securityContext);
6768
}
@@ -126,7 +127,7 @@ public Response logoutUser(@Context SecurityContext securityContext)
126127
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class),
127128

128129
@io.swagger.annotations.ApiResponse(code = 404, message = "User not found", response = Void.class) })
129-
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) User user,@Context SecurityContext securityContext)
130+
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext)
130131
throws NotFoundException {
131132
return service.updateUser(username,user,securityContext);
132133
}

samples/server/petstore/jaxrs-resteasy/eap-java8/src/gen/java/org/openapitools/api/PetApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.ws.rs.core.SecurityContext;
2020
import javax.ws.rs.*;
2121
import javax.validation.constraints.*;
22+
import javax.validation.Valid;
2223
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2324

2425
@Path("/pet")
@@ -40,7 +41,7 @@ public interface PetApi {
4041
}, tags={ "pet", })
4142
@io.swagger.annotations.ApiResponses(value = {
4243
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
43-
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
44+
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
4445
@DELETE
4546
@Path("/{petId}")
4647

@@ -114,7 +115,7 @@ public interface PetApi {
114115
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class),
115116

116117
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
117-
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
118+
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
118119
@POST
119120
@Path("/{petId}")
120121
@Consumes({ "application/x-www-form-urlencoded" })

samples/server/petstore/jaxrs-resteasy/eap-java8/src/gen/java/org/openapitools/api/StoreApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.ws.rs.core.SecurityContext;
1919
import javax.ws.rs.*;
2020
import javax.validation.constraints.*;
21+
import javax.validation.Valid;
2122

2223
@Path("/store")
2324

@@ -67,5 +68,5 @@ public interface StoreApi {
6768
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Order.class),
6869

6970
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid Order", response = Void.class) })
70-
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) Order order,@Context SecurityContext securityContext);
71+
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) @NotNull @Valid Order order,@Context SecurityContext securityContext);
7172
}

samples/server/petstore/jaxrs-resteasy/eap-java8/src/gen/java/org/openapitools/api/UserApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.ws.rs.core.SecurityContext;
1919
import javax.ws.rs.*;
2020
import javax.validation.constraints.*;
21+
import javax.validation.Valid;
2122

2223
@Path("/user")
2324

@@ -33,23 +34,23 @@ public interface UserApi {
3334
@io.swagger.annotations.ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })
3435
@io.swagger.annotations.ApiResponses(value = {
3536
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
36-
public Response createUser(@ApiParam(value = "Created user object" ,required=true) User user,@Context SecurityContext securityContext);
37+
public Response createUser(@ApiParam(value = "Created user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext);
3738
@POST
3839
@Path("/createWithArray")
3940

4041

4142
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
4243
@io.swagger.annotations.ApiResponses(value = {
4344
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
44-
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext);
45+
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext);
4546
@POST
4647
@Path("/createWithList")
4748

4849

4950
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
5051
@io.swagger.annotations.ApiResponses(value = {
5152
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
52-
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext);
53+
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext);
5354
@DELETE
5455
@Path("/{username}")
5556

@@ -99,5 +100,5 @@ public interface UserApi {
99100
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class),
100101

101102
@io.swagger.annotations.ApiResponse(code = 404, message = "User not found", response = Void.class) })
102-
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) User user,@Context SecurityContext securityContext);
103+
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext);
103104
}

samples/server/petstore/jaxrs-resteasy/eap-joda/src/gen/java/org/openapitools/api/PetApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.ws.rs.core.SecurityContext;
2020
import javax.ws.rs.*;
2121
import javax.validation.constraints.*;
22+
import javax.validation.Valid;
2223
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2324

2425
@Path("/pet")
@@ -40,7 +41,7 @@ public interface PetApi {
4041
}, tags={ "pet", })
4142
@io.swagger.annotations.ApiResponses(value = {
4243
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
43-
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
44+
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
4445
@DELETE
4546
@Path("/{petId}")
4647

@@ -114,7 +115,7 @@ public interface PetApi {
114115
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class),
115116

116117
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
117-
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
118+
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
118119
@POST
119120
@Path("/{petId}")
120121
@Consumes({ "application/x-www-form-urlencoded" })

samples/server/petstore/jaxrs-resteasy/eap-joda/src/gen/java/org/openapitools/api/StoreApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.ws.rs.core.SecurityContext;
1919
import javax.ws.rs.*;
2020
import javax.validation.constraints.*;
21+
import javax.validation.Valid;
2122

2223
@Path("/store")
2324

@@ -67,5 +68,5 @@ public interface StoreApi {
6768
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Order.class),
6869

6970
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid Order", response = Void.class) })
70-
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) Order order,@Context SecurityContext securityContext);
71+
public Response placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true) @NotNull @Valid Order order,@Context SecurityContext securityContext);
7172
}

samples/server/petstore/jaxrs-resteasy/eap-joda/src/gen/java/org/openapitools/api/UserApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import javax.ws.rs.core.SecurityContext;
1919
import javax.ws.rs.*;
2020
import javax.validation.constraints.*;
21+
import javax.validation.Valid;
2122

2223
@Path("/user")
2324

@@ -33,23 +34,23 @@ public interface UserApi {
3334
@io.swagger.annotations.ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })
3435
@io.swagger.annotations.ApiResponses(value = {
3536
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
36-
public Response createUser(@ApiParam(value = "Created user object" ,required=true) User user,@Context SecurityContext securityContext);
37+
public Response createUser(@ApiParam(value = "Created user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext);
3738
@POST
3839
@Path("/createWithArray")
3940

4041

4142
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
4243
@io.swagger.annotations.ApiResponses(value = {
4344
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
44-
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext);
45+
public Response createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext);
4546
@POST
4647
@Path("/createWithList")
4748

4849

4950
@io.swagger.annotations.ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
5051
@io.swagger.annotations.ApiResponses(value = {
5152
@io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = Void.class) })
52-
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) List<User> user,@Context SecurityContext securityContext);
53+
public Response createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true) @NotNull @Valid List<User> user,@Context SecurityContext securityContext);
5354
@DELETE
5455
@Path("/{username}")
5556

@@ -99,5 +100,5 @@ public interface UserApi {
99100
@io.swagger.annotations.ApiResponse(code = 400, message = "Invalid user supplied", response = Void.class),
100101

101102
@io.swagger.annotations.ApiResponse(code = 404, message = "User not found", response = Void.class) })
102-
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) User user,@Context SecurityContext securityContext);
103+
public Response updateUser( @PathParam("username") String username,@ApiParam(value = "Updated user object" ,required=true) @NotNull @Valid User user,@Context SecurityContext securityContext);
103104
}

samples/server/petstore/jaxrs-resteasy/eap/src/gen/java/org/openapitools/api/PetApi.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import javax.ws.rs.core.SecurityContext;
2020
import javax.ws.rs.*;
2121
import javax.validation.constraints.*;
22+
import javax.validation.Valid;
2223
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
2324

2425
@Path("/pet")
@@ -40,7 +41,7 @@ public interface PetApi {
4041
}, tags={ "pet", })
4142
@io.swagger.annotations.ApiResponses(value = {
4243
@io.swagger.annotations.ApiResponse(code = 405, message = "Invalid input", response = Void.class) })
43-
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
44+
public Response addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
4445
@DELETE
4546
@Path("/{petId}")
4647

@@ -114,7 +115,7 @@ public interface PetApi {
114115
@io.swagger.annotations.ApiResponse(code = 404, message = "Pet not found", response = Void.class),
115116

116117
@io.swagger.annotations.ApiResponse(code = 405, message = "Validation exception", response = Void.class) })
117-
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) Pet pet,@Context SecurityContext securityContext);
118+
public Response updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true) @NotNull @Valid Pet pet,@Context SecurityContext securityContext);
118119
@POST
119120
@Path("/{petId}")
120121
@Consumes({ "application/x-www-form-urlencoded" })

0 commit comments

Comments
 (0)