-
Notifications
You must be signed in to change notification settings - Fork 146
4. 配置demo
tangcent edited this page Aug 11, 2019
·
1 revision
#yapi mock规则---------------------------------------
#mockjs官方示例: http://mockjs.com/examples.html
#定义一些基础的规则
#手机号
phone=1@pick(["34","35","36","37","38","39","50","5","52","58","59","57","82","87","88","70","47","30","3","32","55","56","85","86","33","53","80","89"])@string("number", 8)
#毫秒时间戳
mtimestamp=@timestamp@string("number", 3)
#0-9
digit=@natural(0,9)
#小于1000的自然数
natural_lt_1000=@natural(0,1000)
#小数点后两位
float_with_two=@natural(0,10000).@natural(0,100)
#mj-img
img=@string("0123456789abcdef",32,32).@pick(["gif","bmp","jpg","jpeg","png"])
#http url
http_url=@pick(["http","https"])://www.@domain()/@string('lower',1,8)?@string('lower',2,4)=@string('number',1,2)
#objectId 只是字符和位数,不满足具体协议
objectId=@string("0123456789abcdef",24,24)
#常见的响应mock
mock.[c|integer]=0
mock.[code|integer]=0
mock.[status|integer]=0
mock.[ok|boolean]=true
mock.[success|boolean]=true
mock.[m|string]=
mock.[msg|string]=
mock.[message|string]=
mock.[errMsg|string]=
#常见的分页mock
mock.[*.p|integer]=1
mock.[*.l|integer]=@pick(["10","15","100"])
mock.[*.t|integer]=@natural(0,1000)
mock.[*.offset|integer]=1
mock.[*.limit|integer]=@pick(["10","15","100"])
mock.[*.total|integer]=@natural(0,1000)
# 整型的xxxTime mock为时间戳
mock.[*Time|integer]=${mtimestamp}
#性别
mock.[*.sex|integer]=@natural(0,2)
mock.[*.sex|string]=@pick(["男","女"])
//用户信息相关
mock.[*.phone|string]=${phone}
mock.[*Phone|string]=${phone}
mock.[*.provinceName|string]=@province
mock.[*ProvinceName|string]=@province
mock.[*.cityName|string]=@city
mock.[*CityName|string]=@city
mock.[*.districtName|string]=@county
mock.[*DistrictName|string]=@county
mock.[*.address]=@cword(2,3)路@natural(1,1500)号
#链接
mock.[*.url|string]=${http_url}
mock.[*.link|string]=${http_url}
mock.[*.linkUrl|string]=${http_url}
mock.[*Link|string]=${http_url}
# integer和number更自然一些
mock.[*Type|integer]=${digit}
mock.[*Status|integer]=${digit}
mock.[*.type|integer]=${digit}
mock.[*.status|integer]=${digit}
mock.[*|integer]=@natural(0,10000)
mock.[*|number]=@float(0,10000)
# @表示注解 #表示注释tag
#从注释上获取module,即要导入到yapi的哪个项目
module=#module
#忽略不解析
ignore=#ignore
#额外的json解析规则
#支持jackson注解
json.rule.field.name=@com.fasterxml.jackson.annotation.JsonProperty#value
#ObjectId和Date处理为String
json.rule.convert[org.bson.types.ObjectId]=java.lang.String
json.rule.convert[java.util.Date]=java.lang.String