1 idea安装easyYapi插件
确认插件使用最新版本:>=2.3.8
参考:easyYapi使用介绍
能正常导出http接口的文档到yapi
2 修改yapi的配置
a . 取消勾选 Preferences(Settings) > Other Settings > EasyApi > Support > methodDoc
b. 勾选 Preferences(Settings) > Other Settings > EasyApi > Support > generic export
c. 勾选Preferences(Settings) > Other Settings > EasyApi > Recommend > import_spring_properties
d. 在Preferences(Settings) > Other Settings > EasyApi > BuiltinConfig或者本地文件引入配置:
# shenyu dubbo client
properties.additional=${module_path}/src/main/resources/sit_dev/application.yml
properties.additional=${module_path}/src/main/resources/sit_dev/application.yaml
generic.class.has.api=@org.apache.dubbo.config.annotation.Service
generic.class.has.api=@org.apache.dubbo.config.annotation.DubboService
generic.method.has.api=@org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient
class.prefix.path=${shenyu.client.props.contextPath}
generic.path[groovy:it.contextType()=="method"]=groovy:it.name()
#before parse method
api.method.parse.before=groovy:```
def isPost=it.argCnt()==1&&!(it.argTypes()[0]).isNormalType()
def isGet=(it.argCnt()==0||it.args().every{it.type().isNormalType()})||regex.contains("^(get|select|query|find).*",it.name())
localStorage.set("isPost",isPost)
localStorage.set("isGet",isGet)
```
generic.http.method[groovy:it.contextType()=="method"]=groovy:```
if(localStorage.get("isGet")){
return "GET"
}
if(localStorage.get("isPost")){
return "POST"
}
return "OPTIONS"
```
# parse param
generic.param.as.json.body=groovy:```
if(localStorage.get("isPost")){
return true
}
if(localStorage.get("isGet")){
return false
}
if(it.type().isNormalType()){
return false
}
return true
```
generic.param.as.form.body=false
# result
method.return=groovy:```
def actualReturnType="com.myhexin.result.ResultApiDto"
if(it.returnType().isExtend("com.myhexin.result.Result")){
def respclassname=tool.substringBetween(it.returnType().name(),",",">")
return actualReturnType+"<"+respclassname+">"
}
return it.returntype.name()
```actualReturnType:改成实际格式对应的class, 目前用了com.myhexin.result.ResultApiDto
e. 找个接入shenyu的dubbo接口进行测试
找个对接shenyu的dubbo服务项目,在有@ShenyuDubboClient注解代码的类中使用easy-yapi插件
f. yapi平台查看效果
shenyu dubbo接口规则
接口根据请求方式分为GET和POST两类。
| POST | 1.参数仅为1个 且 是复杂类型(一般为自定义的class) |
| GET |
|
| 无法识别(用OPTIONS表示) | 1.参数为多个(>=2) 且 至少有1个参数是复杂类型 |
上一篇
软件架构note
软件架构note
版权声明:《 ShenyuDubboClient如何快速写yapi文档 》为Saber原创文章,转载请注明出处!
最后编辑:2022-5-27 10:05:06