-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.easy.api.config
92 lines (86 loc) · 3.21 KB
/
.easy.api.config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
method.return.main[groovy:it.returnType().isExtend("com.itangcent.common.dto.Result")]=data
# Support for Jackson annotation JsonView
json.cache.disable=true
api.param.parse.before=groovy:session.set("is-param",true)
api.param.parse.after=groovy:session.remove("is-param")
# Cache the JsonView information at the method level
api.method.parse.before=groovy:```
def jsonViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
//logger.info("method jsonViews:"+jsonViews)
if (jsonViews) {
session.set("json-views", jsonViews)
}
```
api.method.parse.after=groovy:```
session.remove("json-views")
```
# Check if a field should be ignored based on the active JsonView
field.ignore=groovy:```
if(session.get("is-param")){
return false
}
if(it.contextType()!="field"){
return false
}
def jsonViews = session.get("json-views")
//logger.info("field jsonViews:"+jsonViews)
if (jsonViews) {
def fieldViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
if (fieldViews) {
// Return true if none of the field's views are in the active JsonView
return !fieldViews.any{ fieldView-> jsonViews.any{ jsonView-> jsonView.isExtend(fieldView.name) } }
} else {
// If the field has no JsonView annotation, it should be ignored
return true
}
}
return false
```
http.call.before=groovy:logger.info("call:"+request.url()+"\nbody:"+request.body())
yapi.noUpdateDescription=true
method.additional.header=groovy:```
logger.info("it:"+it)
```
method.additional.header[groovy:it.containingClass().name().startsWith("xxxx.xxxx.xxxx.controller")]=groovy:```
logger.info("it:"+it)
for (arg in it.args()) {
logger.info("arg:"+arg)
logger.info("type:"+arg.type())
logger.info("fields:"+arg.type().fields())
for (field in arg.type().fields()) {
def header = field.ann("xxxx.xxxx.xxxx.Header")
logger.info("field: "+field+", annotated with: xxxx.xxxx.xxxx.Annotation, required:"+header)
if (header!=null) {
logger.info("Annotation found on:"+field)
return tool.toJson([
name: header,
value: "{{xxx-xxx-xxx}}",
desc: "xxxx",
required: true,
example: ""
])
}
}
}
```
export.after[#return]=groovy:```
def returnClass = helper.resolveLink(it.doc("return"))
if(returnClass == null){
return
}
def returnObj = returnClass.toObject(true,true,true)
api.setResponseBody([
"@comment": [code: "状态码", data: "数据对象", msg: "返回内容"],
code: 200,
data: returnObj,
msg: "success"
])
```
# 全局认证
method.additional.header={name: "Authorization",demo: "eyJhbGciOiJIUzUxMiJ9.....",desc: "认证Token",required:true}
param.required=@javax.validation.constraints.NotEmpty
yapi.no_update.description=true
json.cache.disable=true
api.param.parse.before=groovy:session.set("isParam",true)
api.param.parse.after=groovy:session.remove("isParam")
json.rule.field.ignore[com.baomidou.mybatisplus.extension.plugins.pagination.Page#records]=groovy:session.get("isParam")