A smart mock server based on Anyproxy, can install by typing
npm install anymocker -g
This illustrate below show how it works:
-
this is a tool using for fine tuning API json response, which based on Anyproxy, so please follow up anyproxy instruction to setup the environment, that's the basis of rules
-
use jsonpath to locate a field in API response
- replace all API's response(json format), make all
name
field equal togithub
, alltext
field equal toanymocker
, that's a global rule
$ anymocker -s save -m $..name=github $..text=anymocker
- replace api
xxx/xxx
response(json format), make allname
field equal togithub
, delete all thetext
field, and then inject a fieldtitle
, valueddevil
, that's a api rule
$ anymocker -s save -a xxx/xxx -m $..name=github -d $..text -i $.title=devil
- when both api and global rules are specified, should notice that for the same field, api will override global, below the api
xxx/xxx
will mocktext
field asgithub
, and for other request(global) will mocktext
field asgitlab
$ anymocker -s save -a xxx/xxx -m $..name=github -d $..text -i $.title=devil -m $..name=gitlab
- only number, string and boolean can be fuzzy
- can randomly return null
- for number, there are chances to amplify and shrink by multiple
- for string, there are chances to get an empty ''
$ anymocker -s save -a xxx/xxx -m $..name=FUZZ -d $..text -i $.title=devil -m $..name=gitlab $..text=FUZZ
if input parameters are like this:
$ anymocker -s save -a api1 -m x -a api2 -m y -i z
you intend to make rules below:
{
"api": {
"api1": {
"mock": [
x
]
},
"api2": {
"mock": [
y
],
"inject": [
z
]
}
}
}
but unfortunately, what you get exactly is:
{
"api": {
"api1": {
"mock": [
x
],
"inject": [
z
]
},
"api2": {
"mock": [
y
]
}
}
}
the latter -i z
will be squashed as an api1
rule, that's because anymocker analisis parameters by order.
so please, to set a parameter at a prior place, or you just want to make it easy, try anymocker -s save -a api1 -m x -i -a api2 -m y -i z