字段解析功能
最后更新时间:2020-10-26

开放平台的API支持解析引用字段的查询语法,可以将返回结构中的特定字段(如id等)解析出更详尽的内容,语法格式为

GET /asset?resolve={"fields":["fieldA","fieldB"]}

其中fieldA和fieldB为需要解析的字段,多个需要解析的字段间以逗号隔开。

以“查询机构”的API为例:

未添加字段解析

请求参数: GET /department

响应参数:

[{
    "defaultRoles": [],
    "roles": [],
    "permissions": [],
    "parent": null,
    "admins": [],
    "name": "DepA_1",
    "company": "5e01aa7a5ee76858e03a490e",
    "createdBy": "5e01aa7a5ee76858e03a490f",
    "createdAt": "2019-12-24T06:06:17.738Z",
    "updatedAt": "2019-12-24T06:06:17.738Z",
    "id": "5e01aad95ee76858e03a587d",
    "children": []
}]

其中company为此机构所属企业的id。

添加字段解析

例如想查询该机构所属企业的的详细信息,则需要解析company字段: 请求参数:

 GET /department?resolve={"fields":["company","parent"]}

响应参数:

[{
    "defaultRoles": [],
    "roles": [],
    "permissions": [],
    "parent": null,
    "admins": [],
    "name": "DepA_1",
    "company": {
        "admins": ["5e01aa7a5ee76858e03a490f"],
        "verified": false,
        "isOperator": true,
        "operators": [],
        "industries": [],
        "permissions": [],
        "name": "ABC",
        "createdAt": "2019-12-24T06:04:47.135Z",
        "updatedAt": "2019-12-24T06:04:47.135Z",
        "id": "5e01aa7a5ee76858e03a490e"
    },
    "createdBy": "5e01aa7a5ee76858e03a490f",
    "createdAt": "2019-12-24T06:06:17.738Z",
    "updatedAt": "2019-12-24T06:06:17.738Z",
    "id": "5e01aad95ee76858e03a587d",
    "children": []
}]

则company的{}中括号中即为解析出来的该机构所属企业的的详细信息。

目前支持解析字段查询的API如下:

GET /application

GET /company

GET /company/:id

GET /department

GET /department/:id

GET /permission

GET /permission/:id

GET /resource

GET /resource/:id

GET /company/:id/resource

GET /user/:id/resource

GET /user/permission/:id

GET /role

GET /role/:id

GET /user

GET /user/:id