Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多层嵌套的返回参数目前能否满足,如果能满足能否给个@ApiRespParams的例子 #1

Closed
baiqirui opened this issue Apr 24, 2018 · 10 comments

Comments

@baiqirui
Copy link

JSON数据如下:
{
code: 0,
data: {
"pageSize":10,
"pageNum":1,
"data": [
{
"id":1,
"name":"test"
}
]
}
}

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

满足,写这个工具当时解决的主要问题之一就是这个,对象的多层嵌套。

看这里
image

ps:前端页面,时间紧迫,我当时偷懒,多层嵌套那个地方没有写递归,所以前端只能显示5层嵌套,我想对大部分业务,足够了,哪天不够了,我随时改下。后台是支持无限层嵌套的

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

看,这就是个两层嵌套的例子,响应参数应该如下:
{
...
data:{
name:"",
age:""
}
...
}

image

@baiqirui
Copy link
Author

看了下你的例子,我这个可能比较特殊, 我的是3层嵌套,而且还是一个List
我的写法目前是这样:
@com.apidoc.annotation.ApiParam(name = "code", dataType = DataType.NUMBER, defaultValue = "0", description = "状态编码"),
@com.apidoc.annotation.ApiParam(name = "message", dataType = DataType.STRING, defaultValue = "", description = "信息提示"),
@com.apidoc.annotation.ApiParam(name = "data", dataType = DataType.OBJECT, defaultValue = "null", description = "响应数据", object = "PageResult"),
@com.apidoc.annotation.ApiParam(name = "pageSize", dataType = DataType.NUMBER, defaultValue = "0", description = "分页条数", belongTo = "PageResult"),
@com.apidoc.annotation.ApiParam(name = "pageNum", dataType = DataType.NUMBER, defaultValue = "0", description = "当前页码", belongTo = "PageResult"),
@com.apidoc.annotation.ApiParam(name = "result", dataType = DataType.ARRAY, defaultValue = "0", description = "结果集", belongTo = "PageResult", object = "ArchiveType"),
@com.apidoc.annotation.ApiParam(name = "typeId", dataType = DataType.STRING, defaultValue = "", description = "归档类型ID", belongTo = "ArchiveType"),
@com.apidoc.annotation.ApiParam(name = "typeName", dataType = DataType.NUMBER, defaultValue = "", description = "归档类型名称", belongTo = "ArchiveType"),

重点看下这一行
@com.apidoc.annotation.ApiParam(name = "result", dataType = DataType.ARRAY, defaultValue = "0", description = "结果集", belongTo = "PageResult", object = "ArchiveType"),

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

是对的,list的话dataType = DataType.ARRAY就可以了,最终都是转化成json,list和数组是一样的,你这样是对的,有什么问题吗? 记得下载最新版的前端 页面 这个文件夹(https://github.com/liupeng328/api-doc/tree/master/src/main/resources/static/apidoc)

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

并不特殊,正常的需求,这个工具我们已经用了半年了,基本坑都踩完了。这是基本需求

@baiqirui
Copy link
Author

方便的能否加下QQ ,这里截图还不会操作 419475374

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

最底下有qq群的啊,加群就行了

@baiqirui
Copy link
Author

嗯,已发群里,有空的话 帮忙看看, 感谢!!!

@baiqirui
Copy link
Author

image

@cvz6
Copy link
Owner

cvz6 commented Apr 24, 2018

已经改为递归实现,参数中的对象支持无限层嵌套,当时这个地方偷懒了。哈哈,今天改过来了

<div class="div-table">
  <!--递归-->
  <div *ngFor="let requestParam of params">
    <!--第1层-->
    <div *ngIf="!requestParam.list">
      <table>
        <tr>
          <td [ngStyle]="{'padding-left':(10+20*index)+'px','color':'red'}">{{requestParam.name}}</td>
          <td *ngIf="require">{{requestParam.required}}</td>
          <td>{{requestParam.dataType}}</td>
          <td>{{requestParam.defaultValue}}</td>
          <td>{{requestParam.description}}</td>
        </tr>
      </table>
    </div>
    <div *ngIf="requestParam.list">
      <table>
        <tr>
          <td [ngStyle]="{'padding-left':(10+20*index)+'px','color':'red'}">{{requestParam.name}}</td>
          <td *ngIf="require">{{requestParam.required}}</td>
          <td>{{requestParam.dataType}}</td>
          <td>{{requestParam.defaultValue}}</td>
          <td>{{requestParam.description}}</td>
        </tr>
      </table>
      <!--第n层-->
      <app-api-param [params]="requestParam.list" [require]="true" [index]="index+1"></app-api-param>
    </div>
  </div>
</div>

@cvz6 cvz6 closed this as completed Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants