[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);
} }