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

查询调用远程函数各种使用场景说明 #467

Open
cloudAndMonkey opened this issue Nov 10, 2022 · 12 comments
Open

查询调用远程函数各种使用场景说明 #467

cloudAndMonkey opened this issue Nov 10, 2022 · 12 comments
Labels

Comments

@cloudAndMonkey
Copy link
Contributor

cloudAndMonkey commented Nov 10, 2022

比如获取当前用户 函数, 示例代码已经有了
1、新增function
/***
* 获取当前用户id
* @param current
* @return
*/
public String getCurrentUserId(@NotNull JSONObject current) {
return FormVerifier.getVisitorId(getSession());
}
2、配置数据库function权限
image

3、GET调用远程函数

独立调用远程函数

{
"name": "jerry",
"aaa":"demoa",
"id()": "sayHello(name)"
}

获取当前用户id

{
"id()": "getCurrentUserId()"
}

# 简化版调用
{
"id@-()": "getCurrentUserId()",
"User": {
"id@": "/id"
},
"tag": "User",
"@Explain": true
}

查询引用

{
"func": {
"@name": "23",
"id()": "sayHello(@name)"
},
"User": {
"id@": "/func/id"
},
"tag": "User"
}

获取当前用户详细信息

{
"func": {
"id()": "getCurrentUserId()"
},
"User:data": {
"id@": "/func/id"
},
"tag": "User",
"@Explain": true
}

# 子查询引用(注意路径,/ 开头是查询 /sql@/xxx, func/xxx 从顶层查询)
{
"func": {
"@name": "23",
"id()": "sayHello(@name)"
},
"sql@": {
"with": true,
"from": "Sys_user_role",
"Sys_user_role": {
"@column": "role_id",
"user_id@": "func/id"
}
},
"Sys_role[]": {
"Sys_role": {
"id{}@": "sql"
},
"page": 0,
"count": 10
},
"@Explain": true
}

inner join引用

{
"@show_reponse": true,
//"@show_reponse_keys": "func,data",
//"@show_reponse_exclude_keys": "func,tag",
"id@-()": "getCurrentUserId()",
"User[]": {
"User": {
"@from@": {
"from": "User_address",
"join": "&/User/id@",
"User_address": {
"user_id@": "id",
"@column": "id:addr_id,user_id,addr"
},
"User": {
"id@": "/User_address/user_id",
"@column": "id,username"
}
}
}
},
"@Explain": true
}

分组引用

@TommyLemon
Copy link
Collaborator

赞,感谢分享~
最后的分组引用似乎没写完

@TommyLemon
Copy link
Collaborator

{
  "id@-()": "getCurrentUserId()",  //  会得到 "id@": 1 这样
  "User": {
    "id@": "/id"  // 引用不到
  }
}

这种写法看起来有问题,应该去掉多余的 @ ,改为

{
  "id-()": "getCurrentUserId()",  //  会得到 "id": 1 这样的
  "User": {
    "id@": "/id"  // 可以引用到
  }
}

@cloudAndMonkey
Copy link
Contributor Author

{
  "id@-()": "getCurrentUserId()",  //  会得到 "id@": 1 这样
  "User": {
    "id@": "/id"  // 引用不到
  }
}

这种写法看起来有问题,应该去掉多余的 @ ,改为

{
  "id-()": "getCurrentUserId()",  //  会得到 "id": 1 这样的
  "User": {
    "id@": "/id"  // 可以引用到
  }
}

能引用到,哈哈

@TommyLemon
Copy link
Collaborator

TommyLemon commented Nov 28, 2022

{
  "id@-()": "getCurrentUserId()",  //  会得到 "id@": 1 这样
  "User": {
    "id@": "/id"  // 引用不到
  }
}

这种写法看起来有问题,应该去掉多余的 @ ,改为

{
  "id-()": "getCurrentUserId()",  //  会得到 "id": 1 这样的
  "User": {
    "id@": "/id"  // 可以引用到
  }
}

能引用到,哈哈

确实可以,这是个 bug,别这么用,修复后就这种写法就不行了。
image
https://apijson.cn/api/?send=true&type=JSON&url=http%3A%2F%2Fapijson.cn%3A8080%2Fget&json={%22id@-()%22:%22getCurrentUserId()%22,%22User%22:{%22id@%22:%22%2Fid%22}}

@TommyLemon
Copy link
Collaborator

TommyLemon commented Nov 28, 2022

暂时没看出来是哪里的问题。
要么不应该支持,直接抛异常,要么解析为
"id@": 82001

话说最近 Idea 默认把 tab 缩进等效 4 个空格改成了 2 个,导致不少新增代码的缩进和之前对不上,挺乱的。
GitHub 的 tab 缩进处理和 Idea 又不一样,Idea 上看起来对齐的,到 GitHub 又没对齐。
可能需要专门格式化下所有代码。

https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java#L735-L747
image

@cloudAndMonkey
Copy link
Contributor Author

@TommyLemon
我这边是自己的项目登陆,然后走鉴权,客户端head 存储token
apiauto测试,我咋没看到配置head token的地方呢? 我只看到视频里面,可以将页面信息复制到输入框自动解析
我想要的是 和 postman的环境变量配置,多个接口可以复用
image
其他接口复用:
image

@TommyLemon
Copy link
Collaborator

TommyLemon commented Nov 29, 2022

@TommyLemon 我这边是自己的项目登陆,然后走鉴权,客户端head 存储token apiauto测试,我咋没看到配置head token的地方呢? 我只看到视频里面,可以将页面信息复制到输入框自动解析 我想要的是 和 postman的环境变量配置,多个接口可以复用 image 其他接口复用: image

右上角设置 > 显示请求头。
image

目前仅支持 账号及密码、Cookie 的复用。
可以新增一个按钮,切换为 全局 请求头 ,这样每个接口都默认带上全局请求头。
另外可以新增 脚本 输入框,类似 Postman 的 Sccript 区,支持前置和后置处理,支持单对针对接口和全局。

@TommyLemon
Copy link
Collaborator

另外也支持导入 Postman, Swagger, YApi, Rap 等接口请求及文档

@TommyLemon
Copy link
Collaborator

TommyLemon commented Dec 20, 2022

@TommyLemon 我这边是自己的项目登陆,然后走鉴权,客户端head 存储token apiauto测试,我咋没看到配置head token的地方呢? 我只看到视频里面,可以将页面信息复制到输入框自动解析 我想要的是 和 postman的环境变量配置,多个接口可以复用 image 其他接口复用: image

右上角设置 > 显示请求头。 image

目前仅支持 账号及密码、Cookie 的复用。 可以新增一个按钮,切换为 全局 请求头 ,这样每个接口都默认带上全局请求头。 另外可以新增 脚本 输入框,类似 Postman 的 Sccript 区,支持前置和后置处理,支持单对针对接口和全局。

@cloudAndMonkey
APIAuto 已支持前置、后置 脚本处理,并且粒度支持 用例、账号、全局。
前置脚本
https://github.com/TommyLemon/APIAuto
image

目前需要手动点设置项 显示 执行脚本,或者新增登录测试账号,才会成功加载 账号、全局 执行脚本
image

后置脚本
image

image

前置脚本,通过 HTTP 请求获取参数值,替换原来的参数值
image
image
image

@TommyLemon
Copy link
Collaborator

@cloudAndMonkey 解决了代码编辑框使用快捷键的问题,现在可以正常用了
TommyLemon/APIAuto@8c92283

@TommyLemon
Copy link
Collaborator

已部署到
http://apijson.cn/api
可以直接在线体验了

@cloudAndMonkey
Copy link
Contributor Author

@cloudAndMonkey 解决了代码编辑框使用快捷键的问题,现在可以正常用了 TommyLemon/APIAuto@8c92283

收到

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants