In my REST API PATCH operation, I am using v3 swagger-annotation:2.0.6
I was trying to add more examples as swagger schema for my patch operation PATCH /users/id.
Request Body:
{
"operationList": [
{
"op": "replace",
"path": "/username",
"value": "john1991"
}
]
}
Currently I have following class for request model.
public class UserPatchOp extends PatchOperation {
@Override
@Schema(description = "some description", example = "replace", required = true)
public PatchOperator getOp() {
return super.getOp();
}
@Override
@Schema(description = "some description", example = "/username", required = true)
public String getPath() {
return super.getPath();
}
@Override
@Schema(description = "some description", , example = "john1991", required = true)
public Object getValue() {
return super.getValue();
}
}
In PatchOperation.java
public class PatchOperation {
/**
* {@link PatchOperator} operation to be performed
*/
@Schema(description = "Operation to be performed", required = true)
@JsonProperty
@NotNull
private PatchOperator op;
@Schema(description = "Path to target where operation will be performed", required = true)
@JsonProperty
@Pattern(regexp = "/([/A-Za-z0-9~])*-*", message = "Invalid path. Please follow regex pattern")
private String path;
@Schema(description = "Value used by operation")
@JsonProperty
private Object value;
public PatchOperation() {
}
}
In the swagger document, in UserPatchOp.java I have shown to the end-user that how to replace username.
On swagger, the request bogy comes with this example.
other than username through this patch operation, end-user can update description then path would be /description.
End-user can also update the usergroup from which it belongs to '/usergroups' So in general, same way I want to add more example to swagger schema. But I am not able to do it. Because at one time I can show one example only.
I want to show following multiple operations to the client on swagger page.
{
"operationList": [
{
"op": "replace",
"path": "/username",
"value": "john1991"
},
{
"op": "remove",
"path": "/description"
},
{
"op": "add",
"path": "/memberships"
"value":["1224","8907"]
}
]
}
And entry point method is
@PATCH
@Path("users/{id}")
@Consumes({MediaType.APPLICATION_JSON, APPLICATION_JSON_PATCH_JSON})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = MessageConstants.OK, content = @Content(schema = @Schema(implementation = UserInfo.class))),
@ApiResponse(responseCode = "500", description = MessageConstants.SERVER_ERROR, content = @Content(schema = @Schema(implementation = RestError.class))),
@ApiResponse(responseCode = "400", description = MessageConstants.BAD_REQUEST, content = @Content(schema = @Schema(implementation = RestError.class))),
@ApiResponse(responseCode = "401", description = MessageConstants.UNAUTHORIZED, content = @Content(schema = @Schema(implementation = RestError.class))),
@ApiResponse(responseCode = "404", description = MessageConstants.NOT_FOUND, content = @Content(schema = @Schema(implementation = RestError.class)))})
public Response updatePartialUser(
@Parameter(description = "User Id", required = true) @PathParam("id") String id,
@Parameter(description = "User Update Info", required = true) @Valid PatchOperations<UserPatchOperation> operationList) {
Is there any way, I can add multiple examples for getOP, getPath and getValue method? Thank you.


