如何在Java swagger UI中将对象数组作为参数传递?

时间:2017-01-21 07:32:38

标签: java spring-mvc swagger-ui modelattribute

我需要在java Swagger UI 中传递一个对象数组作为参数。我无法做到。但是,我可以轻松地传递字符串数组作为参数。但无法弄清楚如何传递嵌套在另一个类或DTO中的对象数组。我正在使用Java Spring并开发RESTful webservice。

下面是我在REST api中作为ModelAttribute传递的第一个DTO作为参数:

public class BusinessDetailsDTO {

    private BusinessMembersDTO[] businessMembers;

    public BusinessMembersDTO[] getBusinessMembers() {
        return businessMembers;
    }
    public void setBusinessMembers(BusinessMembersDTO[] businessMembers) {
        this.businessMembers = businessMembers;
    }
}

下面是第二个DTO,其数组在第一个DTO中成为属性:

public class BusinessMembersDTO {

    private String ownerRole;
    private String businessLocation;
    private Long memberId;
    //getter setter below 
}

以下是控制器方法定义:

@ApiOperation(value = "Add business info")
    @RequestMapping(method = RequestMethod.POST, value = "/addBusinessInfo", produces={"application/json"})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Success", response = ResponseEntity.class),
            @ApiResponse(code = 401, message = "Unauthorized"),
            @ApiResponse(code = 403, message = "Forbidden"),
            @ApiResponse(code = 404, message = "Not Found"),
            @ApiResponse(code = 500, message = "Failure") })
    public ResponseEntity<BusinessDetails> addBusinessInfo(@RequestParam(
            @ModelAttribute BusinessDetailsDTO businessDetailsDTO) {

我的问题是,我无法弄明白如何传递ownerRole 中存在的值BusinessMembersDTO虚张声势的用户界面在Array[]成员字段旁边的数据类型列中显示businessMembers

Plz帮助。

1 个答案:

答案 0 :(得分:0)

尝试直接将BusinessDetailsDTO作为响应放在ApiResponse中,如下所示

  

@ApiResponse(代码= 200,消息=&#34;成功&#34;,响应= BusinessDetailsDTO.class)