mmock icon indicating copy to clipboard operation
mmock copied to clipboard

[Feature Request] Parse external streams (file.contents at least) for variable tags

Open Kronopt opened this issue 4 years ago • 1 comments

Hi, I think it would be useful to parse external files for variable tags. This way it would be possible to have the response contents outside the mock definition files and still be able to populate it with fake data.

If this is already possible, I can't seem to find how to do it.

An example:

MMock definition:

request:
  method: GET
  path: "/"
response:
  statusCode: 200
  headers:
    Content-Type:
    - application/json
  body: "{{file.contents(test_payload.json)}}"

test_payload.json:

{"test": "{{fake.Brand}}"}

response:

{"test": "Zoozzy"}

Right now this is the response:

{"test": "{{fake.Brand}}"}

Kronopt avatar Apr 08 '20 14:04 Kronopt

Hi, is this still available?

I am a newbie in Go but I will try to implement this feature, although I was thinking that maybe makes more sense to use another key, eg:

request:
  method: GET
  path: "/"
response:
  statusCode: 200
  headers:
    Content-Type:
    - application/json
  bodyFilePath: test_payload.json

What do you think?

jdvr avatar Feb 10 '21 17:02 jdvr

It would be very nice to have this. Stringified JSON values for the body are hard to work with.

kash66 avatar Feb 23 '23 11:02 kash66

Fixed in https://github.com/jmartin82/mmock/pull/139

Thanks for reporting it!

jmartin82 avatar Feb 26 '23 23:02 jmartin82