${}
placeholder to automatically generate data.shenyu-plugin-mock
org.apache.shenyu.plugin.mock.MockPlugin
pom.xml
file.<dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-spring-boot-starter-plugin-mock</artifactId> <version>${project.version}</version> </dependency>
shenyu-admin
--> BasicConfig --> Plugin --> mock
set Status enable.${}
placeholders to generate random data.${}
supported syntax${int|min-max}
min
to max
, inclusive of min
and max
.${int|10-20}
${double|min-max|format}
min
to max
, formatted according to format
.${double|10-20}
, ${double|10-20.5|%.2f}
${email}
${phone}
${zh|min-max}
min
to max
.${zh|10-20}
${en|min-max}
min
to max
.${en|10-20}
${bool}
boolean
value i.e. true
or false
.${list|[arg1,arg2...]}
${list|[gril,boy]}
will return boy
or girl
${current|format}
format
to format, format
can be default, the default is YYYY-MM-dd HH:mm:ss
.${current}
,${current|YYYY-MM-dd}
${array|item|length}
item
format definition, an array of length length
can be generated. All the above data generation rules can be nested in item
, and the result will be automatically added with []
.${array|{"name":"test"}|3}
result is [{"name":"test"},{"name":"test"},{"name":"test"}]
,${array|{"age":${int|18-65}}|3}
.${expression|expression}
Spel
expressions are currently supported with built-in functions and arguments, which fully replace the old ${} syntax
${expression|#int(min,max)}
Description: Generate random integers from min
to max
, inclusive of min
and max
.
Example: ${expression|#int(1,2)}
${expression|#double(min,max)}
min
to max
, formatted according to format
.${expression|#double(10.5,12.0)}
,${expression|#double(10.5,12.0,'¥%.2f')}
${expression|#email()}
${expression|#phone()}
${expression|zh(min,max)}
min
to max
.${expression|#zh(1,10)}
${expression|#bool()}
boolean
value i.e. true
or false
.${expression|#oneOf(arg1,arg2...)}
${expression|#oneOf('shenyu','number',1)}
will return 'shenyu'
or 'number'
or1
${expression|current()}
format
to format, format
can be default, the default is YYYY-MM-dd HH:mm:ss
.${expression|#current()}
,${expression|#current('YYYY-MM-dd')}
${expression|#array(item,length)}
Description: According to the item
format definition, an array of length length
can be generated.
Example: expression|#array('shenyu',3)
would generate ["shenyu","shenyu","shenyu"]
.
You can use it nested like${expression|#array(#bool(),2)}
or${expression|#array(#array('shenyu',2),2)}
${expression|#req}
${expression|#req.method}
、${expression|#req.queries['query_name']}
、${req.queries.query_name}
、${expression|#req.uri}
。jsonPath
is used when the request body is json . For example ,when the request body is {"name":"shenyu"}
,${expression|#req.json.name}
would return “shenyu”${expression|spel}
${expression|T(java.time.LocalDate).now()}
、${expression|1==1}
It is recommended to use the new ‘${}’ syntax. The old syntax may be removed at an later date.
Function replaceable table:
old | new |
---|---|
${int|min-max} | ${expression|#int(min,max)} |
${double|min-max|format} | ${expression|#double(min,max)} |
${email} | ${expression|#email()} |
${phone} | ${expression|#phone()} |
${zh|min-max} | ${expression|#zh(min,max)} |
${en|min-max} | ${expression|#en(min,max)} |
${list|[arg1,arg2...]} | ${expression|#oneOf(arg1,agr2...)} |
${current|format} | ${expression|#current(format)} |
${bool} | ${expression|#bool()} |
${array|item|length} | ${expression#array(item,length)} |
You do not need to use add ""
on both sides of ${}
, the generated content will be prefixed and suffixed according to the definition of generator