-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: support BodyAsJson for Request in static mapping files. #154
Comments
… value equality via JSON serialization to support JSON object matches in request bodies. Update the proxy recorder to use JsonObjectMatcher to record the mapping for a Request with a BodyAsJson. WireMock-Net#154
I pushed up a PR for this. I did not go as far as supporting BodyAsJson having a single JSON value in the Request mapping model, because I wasn't sure if it drifted too far from the existing design. But I did add a JsonObjectMatcher for JSON body matching without escaped strings, and I set it for use with the proxy recorder when recording a request that has a BodyAsJson. |
Thanks a lot for your PR, however I did solve this issue in a different way, I hope you're not offended ;-) I added code to |
Haha, that's a much bolder refactor! It seems to add some flexibility, so that's great. I wasn't sure you'd want to generalize Pattern that much since it seems to be string in all other places, but I happily defer to your vision. At this point, is IValueMatcher still needed separately from IObjectMatcher? IStringMatcher already has I really appreciate you jumping on this, and we're eager to put it to use. Will you be promoting this version to Nuget or shall we depend on a fork for the time being? |
For now I'll keep the |
And maybe join the gitter @ https://gitter.im/wiremock_dotnet/Lobby |
* JsonMatcher (#154) * small update in example code
New NuGet 1.0.4.2 is uploaded. |
Per comment from @StefH in #153, I'll work on a PR for this:
I think the shortcoming with using the MatcherModelMapper for JSON body matching is that the Pattern must be a string. A static mapping would have to escape out all the double-quotes and do the whole JSON on one line, which really hampers readability.
Let's support the BodyAsJson property on the static mapping Request definition and let it just take an object (and not a Matcher definition). So this would look just like the BodyAsJson in the static mapping Response. BodyAsJson will trigger an exact JSON serialization comparison with the incoming request body. This would be very clean to read and alter in the mapping file, and I think it would well suit a common use case. If more flexibility is needed, the JsonPathMatcher on the Body can be used instead.
Further, if the proxy recorder came across a serializable JSON body in the request, it can record this as a BodyAsJson property for the static mapping file rather than translate it into an ExactMatcher as it currently does. (The drawback we're seeing for the ExactMatcher is that if the recorded call indented the JSON body but a later caller doesn't, we don't get a match.)
The text was updated successfully, but these errors were encountered: