anymocker
v1.0.3
Published
mock server with fuzzy value based on anyproxy
Downloads
3
Readme
anymocker
A smart mock server based on Anyproxy, can install by typing
npm install anymocker -g
This illustrate below show how it works:
Before all
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
Rule detail
here are some examples about defining a rule
- 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
Fuzzy
if you don't want to fake data so painful, you can just put a FUZZ
as the value
- 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
TODO
for multi apis mock, something need to consider:
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