gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

Optional or wildcard switch values #44

Closed ztsmith closed 3 years ago

ztsmith commented 8 years ago

It would be great if there was a way to ignore values that are not important. One possibility would be to use some kind of wildcard.

e.g. config setup with: "switch": [ "Foo", "Bar" ], "mockFile": "data.json"

A request URL of: /example?Foo=1&Bar=2

Would match the files: Foo1Bar2.data.json FooBar2.data.json Foo1Bar.json

Where '*' is a wildcard matching any value. The wildcard would likely need to be some kind of token to avoid filename issues: e.g. Foo_any_Barany

Another approach would be to make switch parameters optional. Effectively making any skipped parameter a wildcard.

The same request URL would match: Bar2.data.json Foo1.data.json

Looking at the code, this would require the setSwitchOptions function to return a collection of switch parameters and values. This would allow different (ordered) permutations of mock file loading to be tried.

Any thoughts? Would this be a major breaking change for some people? If this sounds reasonable and I can find some time, I could put a PR together.

gstroup commented 5 years ago

Looking back through the old issues... I think this one can be solved by using a Regular Expression in the switch. https://github.com/gstroup/apimocker#regexp-support