-
Notifications
You must be signed in to change notification settings - Fork 6k
Adds @Valid to request body for the JavaSpring #4850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If useBeanValidation is active, this change will add Valid annotation to ReqeustBody
|
@wing328 looks good, I copied from here to jaxrs-cxf, but I didn't add an additional shellscript/sample for now. |
|
@huningd Does this also solve the issue #4738? Just want to confirm if your solution does both request body validation and nested attribute validation in a single statement then great. I had done something similar where I used Example: @ApiOperation(
value = "Create Profile",
notes = "Creates a new profile for the given application. ",
response = ProfileStatusResponse.class,
tags = {
"Admin",
}
)
@ApiResponses(
value = {
@ApiResponse(code = 201, message = "Profile created", response = ProfileStatusResponse.class),
@ApiResponse(
code = 400,
message = "Invalid Request Error. Check error entity in the response body for details. ",
response = ProfileStatusResponse.class
),
@ApiResponse(
code = 401,
message = "Authentication Failure ",
response = ProfileStatusResponse.class
),
@ApiResponse(
code = 403,
message = "Authorization Failure ",
response = ProfileStatusResponse.class
),
@ApiResponse(
code = 500,
message = "Internal Server Error. Check error entity in the response body for details. ",
response = ProfileStatusResponse.class
)
}
)
@RequestMapping(
value = "/apps/{id}/profiles",
produces = {"application/vnd.cia.v1+json"},
consumes = {"application/vnd.cia.v1+json"},
method = RequestMethod.POST
)
default ResponseEntity<ProfileStatusResponse> createProfile(
@ApiParam(value = "reference to the parent application", required = true) @PathVariable("id")
String id,
@ApiParam(value = "the profile data", required = true) @Validated @RequestBody
Profile profile) {
// do some magic!
return new ResponseEntity<ProfileStatusResponse>(HttpStatus.OK);
}Then on the Model: /**
* Profile identity, represented by a UUID
*
* @return id
*/
@ApiModelProperty(
example = "1b12555a-0e17-4f6f-a5fe-5fcc2be01c97",
readOnly = true,
value = "Profile identity, represented by a UUID"
)
@Valid
public UUID getId() {
return id;
} |
|
@wing328 any update on this? |
|
Any chance these should also work with @PathVariables, even if I have to add the annotations to the rendered code by hand? |
|
@huningd @JeffAtDeere I'll review again over the weekend. ( @JeffAtDeere I assume you've also reviewed the change and it looks good to you ) |
|
I noticed tab instead of 4-spaces is used for code indentation in some templates. I'll file a separate PR to clean up those. I'll also add |
|
UPDATE: replaced tab with 4-space via #5389, new directory also added to pom.xml for Travis CI to test. |
* Adds Valid annotation for request body (swagger-api#4847) If useBeanValidation is active, this change will add Valid annotation to ReqeustBody * Adds generated samples for bean vaildation in spring boot (swagger-api#4847) * Adds Valid import to Controller * Adds generated code for bean validation change
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
If bean validation is activated this pull request adds @Valid to request body for the JavaSpring generator.
solves #4847
refs #4600