Is it possible to negate value in switchResponses part of config.json?
Let's assume the code:
"switch": ["name", "age"],
"responses": {
"post": {"mockFile": "default.json"}
},
"switchResponses": {
"nameJohnage[NOT]20": {"mockFile": "John.json"},
"nameJohnage20": {"mockFile": "John20.json"}
}
I expect that providing parameters name=John and age=99 would give a response from anyOtherJohn.json
I also thought about skipping the second parameter:
"switch": ["name", "age"],
"responses": {
"post": {"mockFile": "default.json"}
},
"switchResponses": {
"nameJohn": {"mockFile": "John.json"},
"nameJohnage20": {"mockFile": "John20.json"}
}
But, by the documentation apimocker will look for the filename that matches ALL the request parameters. If one does not match, then the base file will be returned. So I guess I would get default.json instead of John.json for parameters name=John and age=99. And I'm not sure what I would get for name=John and age=20
Please advice.
Hi, are you working on a mock responses for a JSON POST request? It looks like that's what you're doing, so you should look at JSONPath. There's some info on the README, and more details here: https://www.npmjs.com/package/JSONPath You should be able to do something like this: '$..[?(@.age!=20)]' @priyagampa added the JSONPath support, and may be able to help you. Does that work for you?
Yes, I'm working on JSON files, the examples above were simplified for better readibility. I'll check JSONPath solution that you provided and will let you know if it works. Thanks,
any luck with the JSON path solution?
Sorry for not updating. I had no chance to try your suggestion yet.
Hi, I failed with that. I'm not sure about the proper syntax. See my (failing) approach below. It's reduced to one parameter for clarity reason.
"switch": "$..details.name",
"responses": {
"post": {"mockFile": "default.json"}
},
"switchResponses": {
"$..details.nameJohn": {"mockFile": "John.json"},
"$..details[?(@.name!=$['John'])]": {"mockFile": "whoever.json"}
}