Swagger doc for api response (type List)
I am using swagger to generate the documentation of my REST API. However I am having problems specifying the responses of some API calls.
This is my code:
@GET
@Path("/self/activities")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all activities created by this user",
notes = "Returns the list that the authenticated user (JWT) has created",
response = Activity.class,
responseContainer = "List")
@ApiResponses(value = {
@ApiResponse(code = 400, response = ErrorResponse.Error.class, responseContainer = "List", message = "There was something wrong in the request and therefore could not be processed (headers, json syntax/content)"),
@ApiResponse(code = 500, response = ErrorResponse.Error.class, responseContainer = "List", message = "Unknown Internal server error")})
public void getActivities(...){...}
And this is the doc that it generates:
"responses" : {
"200" : {
"description" : "successful operation",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Activity"
}
}
},
"400" : {
"description" : "There was something wrong in the request and therefore could not be processed (headers, json syntax/content)",
"schema" : {
"$ref" : "#/definitions/Error"
}
},
"500" : {
"description" : "Unknown Internal server error",
"schema" : {
"$ref" : "#/definitions/Error"
}
}
}
And I do not understand why the error responses are not of type 'Array' like the 200 Response. What I want is that all the responses have the same format as the 200 responses (array with items):
"500" : {
"description" : "Uknown interval server error",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Error"
}
}
}
Thanks for your time.
@ApiResponse(code = 400, response = ErrorResponse.Error.class, responseContainer = "List", message = "There was something wrong in the request and therefore could not be processed (headers, json syntax/content)"),
@ApiResponse(code = 500, response = ErrorResponse.Error.class, responseContainer = "List", message = "Unknown Internal server error")})
400 and 500 errors response will return an ErrorResponse. Not an array.
链接地址: http://www.djcxy.com/p/86670.html