mmock icon indicating copy to clipboard operation
mmock copied to clipboard

mappings API needs some love

Open ghost opened this issue 5 years ago • 2 comments

File definitions seem to be ok, but working with API is almost impossible. Simple example:

docker run --rm -p 8082:8082 -p 8083:8083 jordimartin/mmock`
> curl -d '{"request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo 
> {"result":"created"}

Is it really created?

2020/07/02 22:38:08 Changes detected in mock definitions  DIRECTORY "config" WRITE [/config]
2020/07/02 22:38:08 Error Not valid config reader found. Loading config: /foo

I don't speak go to troubleshoot this but let's try something very naive:

> curl -d '{"request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo.json
> {"result":"created"}

Logs:

2020/07/02 22:39:22 Loading config file: /config/foo.json
2020/07/02 22:39:22 Invalid mock format in: /config/foo.json Err: invalid value for delay, got: map[string]interface {}
2020/07/02 22:39:22 Error invalid value for delay, got: map[string]interface {}. Loading config: /foo.json

I don't think swagger.json even mentiones this endpoint BTW.

I thought you should know

ghost avatar Jul 02 '20 22:07 ghost

I've seen something similar on delay - I think it's because something internal converts it from 2s (for example) to {"delay": 2000000}. Seems like that's happening before something that tries to validate the delay as a string in the right format.

mcintyre94 avatar Jul 29 '20 16:07 mcintyre94

I've made POST and PUT api/mapping endpoints to work okay with JSON definitions (with some drawbacks, but I'm completely newbie in golang), as well as I've tried to fix delays handling in my fork (https://github.com/leon-id/mmock), so you could try your usecases. It is necessary to add .json to mock name, and you should directly declare URI in mock definition: curl -d '{"URI":"foo.json", "request": {"method": "GET", "path": "/foo"}, "response": {"statusCode": 200}}' -X POST http://localhost:8082/api/mapping/foo.json

leon-id avatar Jul 31 '20 21:07 leon-id