Forum Discussion

LeonardLai's avatar
LeonardLai
Occasional Contributor
6 years ago

Question about Swagger 2.X Annotations

Hi 

 

I want to use Object(like sample below :Contractor) to get input values from the frontend.


May I use the @RequestBody annotation to define which parameters will pass(not all parameters in the Object)

from the frontend?

 

@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response insert(@RequestBody(description = "Created contractor object", required = true,
            content = @Content(
                    schema = @Schema(implementation = Contractor.class)))Contractor contractor) {
...
}

 

Thanks

 

  • assuming this in scope of usage of swagger-core to resolve an OpenAPI spec from a JAXRS project, you can indeed use @RequestBody (in the specific case you can even skip that, as the parameter Type will be resolved as requestBody); If you need to hide specific properties (if this is what you mean with "not all parameters in the Object") in Contractor, you can add @Hidden annotations there to the properties you want to hide.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Is swagger definition available? Then swagger code gen utility can be used to generate stubs.