muratcorlu / connect-api-mocker

Connect middleware that creates mocks for REST APIs
Apache License 2.0
271 stars 18 forks source link

[Feature Request] Add wildcard support for json files #52

Open BennyAlex opened 4 years ago

BennyAlex commented 4 years ago

Hello,

it would be cool if the wildcard is passed into the json files to, so { id: __project_uuid__ } will return the current uuid.

Maybe the wildcard needs some type of escaping, eg: $__project_uuid__$

This would reduce the usage of more complicated js files.

muratcorlu commented 4 years ago

Hi,

That's a good one. And also doesn't seem very difficult to implement. The most important part deciding a notation for variables in json files. I'll think about it. Any other suggestions and even PRs are very welcome.

BennyAlex commented 4 years ago

json needs for all keys/values strings, so maybe __id__ without quotes is enough

BennyAlex commented 4 years ago

you are already introduced a wildcard notation with double underscore, so you probably fine using it again

muratcorlu commented 4 years ago

I'm not sure about "not using" quotes because in that case json files will be invalid and it can disturb people on editors or some linters. Maybe

{
  "id": "__id__"
}

will be also good and safe enough.

BennyAlex commented 4 years ago

yeah you are right. Another cool thing would be usage of simple expressions

{ 'doubleID': 'mockExpresion(__uuid__ * 2)' }

where 'mockExpresion' indicates the value is an expression

BennyAlex commented 4 years ago

But {"id": "__id__"} would be already nice and I think its okay to turn it on by default, but maybe the user can disable it with an option passed to the mock config