java – 用于api响应的Swagger doc(类型List)

我正在使用swagger来生成我的REST API的文档.但是,我在指定某些API调用的响应时遇到问题.

这是我的代码

@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(...){...}

这是它生成的文档:

"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"
        }
      }
    }

我不明白为什么错误响应不像200响应那样是’Array’类型.我想要的是所有响应的格式与200响应(带项目的数组)相同:

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

谢谢你的时间.

解决方法

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

400和500错误响应将返回ErrorResponse.不是数组.

相关文章

ArrayList简介:ArrayList 的底层是数组队列,相当于动态数组。与 Java 中的数组相比,它的容量能动态增...
一、进程与线程 进程:是代码在数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位。 线程...
本文为博客园作者所写: 一寸HUI,个人博客地址:https://www.cnblogs.com/zsql/ 简单的一个类...
#############java面向对象详解#############1、面向对象基本概念2、类与对象3、类和对象的定义格式4、...
一、什么是异常? 异常就是有异于常态,和正常情况不一样,有错误出错。在java中,阻止当前方法或作用域...
Collection接口 Collection接口 Collection接口 Collection是最基本的集合接口,一个Collection代表一组...