Java – swagger doc (type list) for API response

I'm using swagger to document my rest API However, I encountered a problem specifying the response for 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,message = "UnkNown Internal server error")})
public void getActivities(...){...}

This is the document 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"
        }
      }
    }

I don't understand why the error response is not of type 'array' like the 200 response What I want is that the format of all responses is the same as that of 200 responses (array with items):

"500" : {
        "description" : "UkNown interval server error","items" : {
            "$ref" : "#/deFinitions/Error"
          }
        }
      }

Thank you for your time

Solution

@ApiResponse(code = 400,message = "UnkNown Internal server error")})
@ApiResponse(code = 400,message = "UnkNown Internal server error")})

400 and 500 error responses will return errorresponse Not an array

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>