dreamhead / moco

Easy Setup Stub Server
MIT License
4.35k stars 1.08k forks source link

The json in the configuration request needs to match all the json in the body in order for the test to pass #343

Closed lqz2012 closed 7 months ago

lqz2012 commented 9 months ago

When configured as queries parameter, only the parameters in the configuration need to be matched when calling, and the test can pass. config: [{"request":{"uri":"/test","queries":{"key":"test1"}},"response":{"text":"success"}}] test: curl http://ip:12305/test?key=test1&name=a

When configured as a json parameter, all parameters in the body json need to be matched when calling to pass the test, otherwise the test will not pass. config: [{"request":{"uri":"/test","json":{"key":"test1"}},"response":{"text":"success"}}]

test1, pass curl -X POST http://ip:12305/test -H "Content-type: application/json" -d' { "key": "test1" } '

test2, fail curl -X POST http://ip:12305/test -H "Content-type: application/json" -d' { "key": "test1", "name": "a" } '

How can I make json parameters like queries parameters and pass the test only if they match the parameters in the configuration?

dreamhead commented 9 months ago

struct allows you to match a JSON request only for same struct no matter what actual content is.

jsonPath allows you to match request with JSONPath.

lqz2012 commented 9 months ago

struct allows you to match a JSON request only for same struct no matter what actual content is.

jsonPath allows you to match request with JSONPath.

Yes, JSONPath can solve this problem, thank you very much