跳转至

设计时 API 中心管理(ApiDesignTimeController)

API 中心 .api 资源的设计时管理:列表查询、详情获取、新建、更新与批量删除。每条 API 配置(ApiConfig)隶属于一个 API 分组(apiGroup),并可配置请求类型、响应类型、标签、请求脚本与响应脚本等。

  • 接口类型:REST 资源
  • 基址:${myapps.context-path.designer:}/api/designtime/applications(类级 @RequestMapping,produces = APPLICATION_JSON_VALUE)
  • Tag:API中心操作模块

公共说明

  • 鉴权:是(需 designerToken)。控制器继承自 AbstractDesignTimeController(基类为 @RestController),通过 Security.getDesignerIdFromToken(request) 从 designerToken JWT 中解析设计器用户。鉴权机制详见 index.md「鉴权说明」。
  • 路径变量:{applicationId}、{apiId} 均为**明文设计时 ID**。
  • 响应:统一 Resource(见 ../index.md「统一响应结构」)。成功 errcode=0;保存时抛 OBPMValidateException(未选分组、名称重复)返回 errcode=40001;其他异常 errcode=500。
  • HTTP 方法:受 CommonSecurityFilter 限制,仅允许 GET/POST/HEAD/OPTIONS。
  • 请求体约定:POST/PUT 接收原始 JSON 字符串(@RequestBody String content),由服务端用 JSONObject.fromObject 解析后通过 json2obj 转 ApiConfig;DELETE 接收原始 JSON 字符串(@RequestBody String content),由 com.jayway.jsonpath.JsonPath.parse(content).json() 反序列化为 List<String>(与多数控制器接收 String[] 不同)。
  • 隶属关系:新建时 parentId 取自 apiGroup 字段(即 API 分组Id)。

1. 获取 API 列表

分页获取指定应用下的 API 列表,可按名称、API 分组、请求类型、状态等多条件过滤。

  • 接口类型:REST 资源
  • 请求方式:GET
  • 请求路径:/{applicationId}/apis(完整:{designer-context}/api/designtime/applications/{applicationId}/apis)
  • 鉴权:是(需 designerToken)
  • Tag:API中心操作模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 是 应用Id
name query string 否 按名称查询关键字
apiGroupId query string 否 API 分组Id
requestType query string 否 请求类型
status query string 否 状态
pageNo query int 否 页码(缺省 1)
linesPerPage query int 否 每页条数(缺省 10)

说明:以上 query 参数均标注 @RequestParam(required = false),故均可缺省;pageNo/linesPerPage 提供 defaultValue。

请求示例

GET /api/designtime/applications/{applicationId}/apis?name=&apiGroupId=&requestType=&status=&pageNo=1&linesPerPage=10 HTTP/1.1

响应

结构:统一 Resource(见 ../index.md「统一响应结构」)。 data:DataPackage<ApiConfig>(含分页字段与 datas)。

成功示例:

{
  "errcode": 0,
  "errmsg": "ok",
  "data": {
    "linesPerPage": 10,
    "pageNo": 1,
    "pageCount": 1,
    "rowCount": 1,
    "datas": [
      { "id": "...", "name": "API 名称", "requestType": "...", "requestUrl": "...", "status": "...", "apiGroup": "...", "...": "..." }
    ]
  },
  "errors": null
}
失败示例:
{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }


2. 获取 API 详情

按 API Id 获取完整 API 配置对象。

  • 接口类型:REST 资源
  • 请求方式:GET
  • 请求路径:/{applicationId}/apis/{apiId}
  • 鉴权:是(需 designerToken)
  • Tag:API中心操作模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 是 应用Id
apiId path string 是 API 主键Id

响应

data:ApiConfig 完整对象。

{ "errcode": 0, "errmsg": "ok", "data": { "id": "...", "name": "...", "requestType": "...", "requestUrl": "...", "responseScript": "...", "...": "..." }, "errors": null }
失败示例:
{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }


3. 新建 API

在指定应用下新建 API。请求体解析为 ApiConfig 后强制覆盖 applicationid(取路径 applicationId)、parentId(取 apiGroup 字段),保存前做分组非空与重名校验。HTTP 状态码 201。

  • 接口类型:REST 资源
  • 请求方式:POST
  • 请求路径:/{applicationId}/apis
  • 鉴权:是(需 designerToken)
  • Tag:API中心操作模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 是 应用Id
content body string(JSON) 是 API 对象 JSON

请求体

对应 ApiConfig 对象 JSON(name、apiGroup、requestType、requestUrl、status、tags、encode、responseScript、responseType 等)。

{ "name": "<API 名>", "apiGroup": "<分组Id>", "requestType": "GET", "requestUrl": "...", "status": "...", "tags": "...", "encode": "...", "responseType": "...", "responseScript": "..." }

响应

data:JSONObject,仅含 id(新建 API Id)。

{ "errcode": 0, "errmsg": "ok", "data": { "id": "<API Id>" }, "errors": null }
失败示例(未选分组):
{ "errcode": 40001, "errmsg": "请选择API分组!", "data": null, "errors": null }
失败示例(重名):
{ "errcode": 40001, "errmsg": "名称已经存在!", "data": null, "errors": null }
失败示例(其他异常):
{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }


4. 更新 API

按 API Id 更新 API 对象。先按 apiId 查出原对象并克隆,再用请求体中的 name/status/tags/requestType/requestUrl/encode/responseScript/responseType/apiGroup 覆盖(其余字段保留原值),强制清空 uri 后保存。HTTP 状态码 201(源码 @ResponseStatus(HttpStatus.CREATED),更新场景亦返回 201)。

  • 接口类型:REST 资源
  • 请求方式:PUT
  • 请求路径:/{applicationId}/apis/{apiId}
  • 鉴权:是(需 designerToken)
  • Tag:API中心操作模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 是 应用Id
apiId path string 是 API Id(用于查找原对象)
content body string(JSON) 是 API 对象 JSON

请求体

对应 ApiConfig 对象 JSON(字段同新建,仅上述列举字段会被采用)。

{ "name": "<API 名>", "apiGroup": "<分组Id>", "requestType": "...", "requestUrl": "...", "status": "...", "tags": "...", "encode": "...", "responseType": "...", "responseScript": "..." }

响应

data:null(成功)。

{ "errcode": 0, "errmsg": "ok", "data": null, "errors": null }
失败示例(校验失败):
{ "errcode": 40001, "errmsg": "<校验信息>", "data": null, "errors": null }
失败示例(其他异常):
{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }


5. 删除 API(可批量)

按 API Id 数组批量删除 API(删除前收集各 API 的路径信息)。请求体为 JSON 字符串(由 JsonPath 反序列化为 List<String>)。

  • 接口类型:REST 资源
  • 请求方式:DELETE
  • 请求路径:/{applicationId}/apis
  • 鉴权:是(需 designerToken)
  • Tag:API中心操作模块

请求参数

参数名 位置 类型 必填 说明
applicationId path string 是 应用Id
content body string(JSON) 是 API Id 字符串数组(JSON 数组形式)

请求体

["<apiId1>", "<apiId2>"]

响应

data:String,固定为 "删除成功"。

{ "errcode": 0, "errmsg": "ok", "data": "删除成功", "errors": null }
失败示例:
{ "errcode": 500, "errmsg": "<异常信息>", "data": null, "errors": null }