smocker-dev / smocker

Smocker is a simple and efficient HTTP mock server and proxy
https://smocker.dev
MIT License
1.16k stars 61 forks source link

Combined query/body param matcher #278

Closed Powerrr closed 1 year ago

Powerrr commented 1 year ago

Sometimes we don't care if a particular parameter is sent in the query string or in the application/x-www-form-urlencoded body, because the application that we mock can consume that parameter either way. For such a case it would be nice if there was a way to setup a mock using some combined condition, smth. like

- request:
    method: POST
    path: /foobar
    query_or_body_params:
      qwe: asd
  response:
    body: ok

so that it would match both POST /foobar?qwe=asd and POST -H 'Content-type: application/x-www-form-urlencoded' /foobar --data 'qwe=asd'. Basically, it would look for the qwe param both in the query and in the body.

(Currently my workaround is adding 2 mocks: one matches the query, another matches the body.)

So is it possible to add a feature like this?

gwleclerc commented 1 year ago

Hello, the question of an "or" operator came up when we were designing the way mocks work. And what you present as a workaround was the simplest solution we could find to keep mocks clear and understandable. We should definitely make this clearer in the documentation.

Duplicating may seem a little overkill but on the other hand it ensures exaustive signatures on expected calls.