[Jaxrs-cxf] Add method-level cascaded beanvalidation (@Valid) (#4921)

* add ApiResponse/s to operation #4718

* add method-level cascaded beanvalidation #4847
This commit is contained in:
jfiala 2017-03-23 08:56:23 +01:00 committed by wing328
parent b89e2e6cc3
commit 43aa4a8569
11 changed files with 33 additions and 27 deletions

View File

@ -19,6 +19,7 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH; import io.swagger.jaxrs.PATCH;
{{#useBeanValidation}} {{#useBeanValidation}}
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.Valid;
{{/useBeanValidation}} {{/useBeanValidation}}
@Path("{{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}}") @Path("{{^useAnnotatedBasePath}}/{{/useAnnotatedBasePath}}{{#useAnnotatedBasePath}}{{contextPath}}{{/useAnnotatedBasePath}}")

View File

@ -28,7 +28,7 @@ import org.springframework.stereotype.Service;
public class {{classname}}ServiceImpl implements {{classname}} { public class {{classname}}ServiceImpl implements {{classname}} {
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParamsImpl}}{{>pathParamsImpl}}{{>headerParamsImpl}}{{>bodyParams}}{{>formParamsImpl}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { public {{>returnTypes}} {{nickname}}({{#allParams}}{{>queryParamsImpl}}{{>pathParamsImpl}}{{>headerParamsImpl}}{{>bodyParamsImpl}}{{>formParamsImpl}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
// TODO: Implement... // TODO: Implement...
{{^vendorExtensions.x-java-is-response-void}}return null;{{/vendorExtensions.x-java-is-response-void}} {{^vendorExtensions.x-java-is-response-void}}return null;{{/vendorExtensions.x-java-is-response-void}}

View File

@ -1 +1 @@
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}} {{#isBodyParam}}{{#useBeanValidation}}@Valid {{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/isBodyParam}}

View File

@ -0,0 +1 @@
{{#isBodyParam}}{{{dataType}}} {{paramName}}{{/isBodyParam}}

View File

@ -19,6 +19,7 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH; import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.Valid;
@Path("/") @Path("/")
@Api(value = "/", description = "") @Api(value = "/", description = "")
@ -31,7 +32,7 @@ public interface FakeApi {
@ApiOperation(value = "To test \"client\" model", tags={ "fake", }) @ApiOperation(value = "To test \"client\" model", tags={ "fake", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Client.class) }) @ApiResponse(code = 200, message = "successful operation", response = Client.class) })
public Client testClientModel(Client body); public Client testClientModel(@Valid Client body);
@POST @POST
@Path("/fake") @Path("/fake")

View File

@ -19,6 +19,7 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH; import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.Valid;
@Path("/") @Path("/")
@Api(value = "/", description = "") @Api(value = "/", description = "")
@ -31,7 +32,7 @@ public interface PetApi {
@ApiOperation(value = "Add a new pet to the store", tags={ "pet", }) @ApiOperation(value = "Add a new pet to the store", tags={ "pet", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") }) @ApiResponse(code = 405, message = "Invalid input") })
public void addPet(Pet body); public void addPet(@Valid Pet body);
@DELETE @DELETE
@Path("/pet/{petId}") @Path("/pet/{petId}")
@ -78,7 +79,7 @@ public interface PetApi {
@ApiResponse(code = 400, message = "Invalid ID supplied"), @ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Pet not found"), @ApiResponse(code = 404, message = "Pet not found"),
@ApiResponse(code = 405, message = "Validation exception") }) @ApiResponse(code = 405, message = "Validation exception") })
public void updatePet(Pet body); public void updatePet(@Valid Pet body);
@POST @POST
@Path("/pet/{petId}") @Path("/pet/{petId}")

View File

@ -18,6 +18,7 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH; import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.Valid;
@Path("/") @Path("/")
@Api(value = "/", description = "") @Api(value = "/", description = "")
@ -57,6 +58,6 @@ public interface StoreApi {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class), @ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid Order") }) @ApiResponse(code = 400, message = "Invalid Order") })
public Order placeOrder(Order body); public Order placeOrder(@Valid Order body);
} }

View File

@ -18,6 +18,7 @@ import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.jaxrs.PATCH; import io.swagger.jaxrs.PATCH;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import javax.validation.Valid;
@Path("/") @Path("/")
@Api(value = "/", description = "") @Api(value = "/", description = "")
@ -29,7 +30,7 @@ public interface UserApi {
@ApiOperation(value = "Create user", tags={ "user", }) @ApiOperation(value = "Create user", tags={ "user", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") }) @ApiResponse(code = 200, message = "successful operation") })
public void createUser(User body); public void createUser(@Valid User body);
@POST @POST
@Path("/user/createWithArray") @Path("/user/createWithArray")
@ -37,7 +38,7 @@ public interface UserApi {
@ApiOperation(value = "Creates list of users with given input array", tags={ "user", }) @ApiOperation(value = "Creates list of users with given input array", tags={ "user", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") }) @ApiResponse(code = 200, message = "successful operation") })
public void createUsersWithArrayInput(List<User> body); public void createUsersWithArrayInput(@Valid List<User> body);
@POST @POST
@Path("/user/createWithList") @Path("/user/createWithList")
@ -45,7 +46,7 @@ public interface UserApi {
@ApiOperation(value = "Creates list of users with given input array", tags={ "user", }) @ApiOperation(value = "Creates list of users with given input array", tags={ "user", })
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation") }) @ApiResponse(code = 200, message = "successful operation") })
public void createUsersWithListInput(List<User> body); public void createUsersWithListInput(@Valid List<User> body);
@DELETE @DELETE
@Path("/user/{username}") @Path("/user/{username}")
@ -90,6 +91,6 @@ public interface UserApi {
@ApiResponses(value = { @ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid user supplied"), @ApiResponse(code = 400, message = "Invalid user supplied"),
@ApiResponse(code = 404, message = "User not found") }) @ApiResponse(code = 404, message = "User not found") })
public void updateUser(@PathParam("username") String username, User body); public void updateUser(@Valid @PathParam("username") String username, User body);
} }

View File

@ -80,7 +80,7 @@ public class PetApiTest {
@Test @Test
public void addPetTest() { public void addPetTest() {
Pet body = null; Pet body = null;
//api.addPet(body); //api.addPet(body);
// TODO: test validations // TODO: test validations
@ -99,7 +99,7 @@ public class PetApiTest {
public void deletePetTest() { public void deletePetTest() {
Long petId = null; Long petId = null;
String apiKey = null; String apiKey = null;
//api.deletePet(petId, apiKey); //api.deletePet(petId, apiKey);
// TODO: test validations // TODO: test validations
@ -153,7 +153,7 @@ public class PetApiTest {
@Test @Test
public void getPetByIdTest() { public void getPetByIdTest() {
Long petId = null; Long petId = null;
//Pet response = api.getPetById(petId); //Pet response = api.getPetById(petId);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations
@ -171,7 +171,7 @@ public class PetApiTest {
@Test @Test
public void updatePetTest() { public void updatePetTest() {
Pet body = null; Pet body = null;
//api.updatePet(body); //api.updatePet(body);
// TODO: test validations // TODO: test validations
@ -191,7 +191,7 @@ public class PetApiTest {
Long petId = null; Long petId = null;
String name = null; String name = null;
String status = null; String status = null;
//api.updatePetWithForm(petId, name, status); //api.updatePetWithForm(petId, name, status);
// TODO: test validations // TODO: test validations
@ -211,7 +211,7 @@ public class PetApiTest {
Long petId = null; Long petId = null;
String additionalMetadata = null; String additionalMetadata = null;
org.apache.cxf.jaxrs.ext.multipart.Attachment file = null; org.apache.cxf.jaxrs.ext.multipart.Attachment file = null;
//ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); //ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations

View File

@ -79,7 +79,7 @@ public class StoreApiTest {
@Test @Test
public void deleteOrderTest() { public void deleteOrderTest() {
String orderId = null; String orderId = null;
//api.deleteOrder(orderId); //api.deleteOrder(orderId);
// TODO: test validations // TODO: test validations
@ -114,7 +114,7 @@ public class StoreApiTest {
@Test @Test
public void getOrderByIdTest() { public void getOrderByIdTest() {
Long orderId = null; Long orderId = null;
//Order response = api.getOrderById(orderId); //Order response = api.getOrderById(orderId);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations
@ -132,7 +132,7 @@ public class StoreApiTest {
@Test @Test
public void placeOrderTest() { public void placeOrderTest() {
Order body = null; Order body = null;
//Order response = api.placeOrder(body); //Order response = api.placeOrder(body);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations

View File

@ -79,7 +79,7 @@ public class UserApiTest {
@Test @Test
public void createUserTest() { public void createUserTest() {
User body = null; User body = null;
//api.createUser(body); //api.createUser(body);
// TODO: test validations // TODO: test validations
@ -97,7 +97,7 @@ public class UserApiTest {
@Test @Test
public void createUsersWithArrayInputTest() { public void createUsersWithArrayInputTest() {
List<User> body = null; List<User> body = null;
//api.createUsersWithArrayInput(body); //api.createUsersWithArrayInput(body);
// TODO: test validations // TODO: test validations
@ -115,7 +115,7 @@ public class UserApiTest {
@Test @Test
public void createUsersWithListInputTest() { public void createUsersWithListInputTest() {
List<User> body = null; List<User> body = null;
//api.createUsersWithListInput(body); //api.createUsersWithListInput(body);
// TODO: test validations // TODO: test validations
@ -133,7 +133,7 @@ public class UserApiTest {
@Test @Test
public void deleteUserTest() { public void deleteUserTest() {
String username = null; String username = null;
//api.deleteUser(username); //api.deleteUser(username);
// TODO: test validations // TODO: test validations
@ -151,7 +151,7 @@ public class UserApiTest {
@Test @Test
public void getUserByNameTest() { public void getUserByNameTest() {
String username = null; String username = null;
//User response = api.getUserByName(username); //User response = api.getUserByName(username);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations
@ -170,7 +170,7 @@ public class UserApiTest {
public void loginUserTest() { public void loginUserTest() {
String username = null; String username = null;
String password = null; String password = null;
//String response = api.loginUser(username, password); //String response = api.loginUser(username, password);
//assertNotNull(response); //assertNotNull(response);
// TODO: test validations // TODO: test validations
@ -187,7 +187,7 @@ public class UserApiTest {
*/ */
@Test @Test
public void logoutUserTest() { public void logoutUserTest() {
//api.logoutUser(); //api.logoutUser();
// TODO: test validations // TODO: test validations
@ -206,7 +206,7 @@ public class UserApiTest {
public void updateUserTest() { public void updateUserTest() {
String username = null; String username = null;
User body = null; User body = null;
//api.updateUser(username, body); //api.updateUser(username, body);
// TODO: test validations // TODO: test validations