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

[Question] GET请求的枚举字段通过脚本自定义备注后如何忽略原来的备注信息? #1158

Open
benny-zhou opened this issue Aug 19, 2024 · 1 comment
Labels
type: question&discussion Further information is requested

Comments

@benny-zhou
Copy link

benny-zhou commented Aug 19, 2024

springboot3构建的项目,通过.easy.api.config文件自定义param.doc属性的自定义备注

param.doc=groovy:```
if(!it.type().isExtend("cn.xxx.project.common.model.enums.ValueEnum")){
    return
}
try {
    def enumResolver = runtime.getBean("com.itangcent.intellij.jvm.standard.StandardPsiResolver")
    def docStr = "----------" + """\n"""
    // 填写字典编码  获取字段的Class上的doc的 @dictName
    def fieldClassDocDictName = it.type().doc("dictName")
    def fieldClassDoc = it.type().doc()
    def docDictName = fieldClassDocDictName != null ? fieldClassDocDictName : fieldClassDoc
    if(docDictName != null && docDictName != "" ){
        docStr = docStr + "字典名:" + docDictName + """\n"""
    }

    // 填写字典编码  获取字段的Class上的doc的 @dictCode
    def fieldClassDocDictCode = it.type().doc("dictCode")
    if(fieldClassDocDictCode != null){
        docStr = docStr + "字典编码:" + fieldClassDocDictCode + """\n"""
    }

    docStr = docStr + "枚举属性:" + """\n"""

    def fieldClassEnumFields = it.type().fields()
    fieldClassEnumFields.collect { item -> 
        //logger.info("item name "+ item.name())
        def itemResource = item.getResource()
        //logger.info("itemResource.class.name "+itemResource.class.name)
        if(itemResource.class.name.contains("Enum")){
           //logger.info("item getResource "+ itemResource)
           //logger.info("itemgetResource :"+ enumResolver.resolveEnumFields(0, item.getResource()))
           def enumItemValues = enumResolver.resolveEnumFields(0, item.getResource())
           docStr = docStr + "【"+enumItemValues["params"]["code"] +  "=" + enumItemValues["params"]["text"] + "】" +  """\n"""
        }
    }
    return docStr
} finally {
    localStorage.remove("__reentrant")
}

导出的结果如图:
image

如何才能忽略下方自动凭接的内容呢?

TIKTOK :TIKTOK
DIANPING :DIANPING
KWAI :KWAI

@benny-zhou benny-zhou added the type: question&discussion Further information is requested label Aug 19, 2024
@tangcent
Copy link
Owner

没有这样的规则,现在可以试试强行修改请求内容。

http.call.before=groovy:```
def body = request.body()
if(!request.url().contains("api/interface/save") || body==null){
    return
}
def json = tool.toJson(body)
//logger.info("body: $json")
def cleanedJson = regex.delAll(/,[\\"]*enumDesc[\\"]*:[\\"]*.*?"\\*/,json)
//logger.info("cleanedJson: $cleanedJson")
request.body(cleanedJson)
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question&discussion Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants