Optum / mockiato

A web-based platform for API virtualization
Apache License 2.0
24 stars 9 forks source link

Publishing JSON request with Syntax error should not be allowed #497

Open spant3 opened 5 years ago

spant3 commented 5 years ago

-When I am trying to create a service with attached RR pairs. The service is getting published though the JSON is syntactically not correct. -Json request contains duplicate key elements(providerType and srcCoverage) -Mockiato is allowing to publish the service and it is automatically wiping out the duplicate key enteries. Though the values for the key are different. -It should display a valid error message and should not allow to publish the service.

Provider Type Req-Res.txt

johnlegeyt commented 5 years ago

So, I did some digging, and this is a tricky one. Multiple fields with the same key are not, technically, invalid JSON (nor is it explicitly valid, either.). However, having multiple fields with the same key (that are not an array) is not feasible from a technical perspective for most implementations (most especially in javascript). The parser we use (Just the default JSON.parse) just takes the last one read as the value for that single element. I suspect other parsers we could find do as well.

Unless we want to parse this ourselves, I'm not sure there's a good way around it.