Reputation: 348
How we can define multiple examples for request object just like we define examples for response object as below.
@ApiResponses(value = {
@ApiResponse(code = 200, response = Response.class, message = "Success", examples = @io.swagger.annotations.Example(
value = {
@ExampleProperty(value = "{'key1': 'value1', 'key2':'value2'}", mediaType = "application/json")
}))
})
Upvotes: 2
Views: 3104
Reputation: 35
enhancing "Abhinav manthri" answer using "schema" and using "oneOf" for multiple requests
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(oneOf = { MyReqBody1.class, MyReqBody2.class })) })
Upvotes: 1
Reputation: 348
I couldn't find much in swagger2, but i upgraded to openapi and then given examples as below
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = @ExampleObject(value = "{\"key1\": \"value1\", \"key2\":\"value2\", \"key3\":\"value3\"}"))
})
Upvotes: 2