Request body is missing in generated pact file for requests that include matching on request body #437

Closed
opened 2025-12-29 15:23:47 +01:00 by adam · 4 comments
Owner

Originally created by @shack05 on GitHub (Aug 12, 2022).

Describe the bug

The request body is missing in generated pact file for requests that include matching on request body.
More specifically, I am using the JsonPartialMatcher.

Expected behavior:

The generated pact file includes the expectations of the request body as specified by the matchers used in the wiremock scenario.

Test to reproduce

server
   .WithConsumer("Consumer1")
   .WithProvider("Provider1");

server
   .Given(Request.Create().UsingPost().WithPath("/foo")
      .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }")))
   .WithTitle("Example1")
   .RespondWith(Response.Create().WithStatusCode(201)));

server.SavePact("...")

I'm not sure what the expected pact should look like, but I imagine request body should be included in some way.
The actual pact file is:

{
   "consumer": {
      "name": "Consumer1"
   },
   "interactions": [
      {
         "providerState": "Example1",
         "request": {
            "method": "POST",
            "path": "/foo",
         },
         "response": {
            "status": "201",
         } 
      }
   ],
   "provider": {
      "name": "Provider1"
   }
}

WIremock version - 1.5.3-ci-16331 (from #784).

Originally created by @shack05 on GitHub (Aug 12, 2022). ### Describe the bug The request body is missing in generated pact file for requests that include matching on request body. More specifically, I am using the JsonPartialMatcher. ### Expected behavior: The generated pact file includes the expectations of the request body as specified by the matchers used in the wiremock scenario. ### Test to reproduce ``` CSharp server .WithConsumer("Consumer1") .WithProvider("Provider1"); server .Given(Request.Create().UsingPost().WithPath("/foo") .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }"))) .WithTitle("Example1") .RespondWith(Response.Create().WithStatusCode(201))); server.SavePact("...") ``` I'm not sure what the expected pact should look like, but I imagine request body should be included in some way. The actual pact file is: ``` json { "consumer": { "name": "Consumer1" }, "interactions": [ { "providerState": "Example1", "request": { "method": "POST", "path": "/foo", }, "response": { "status": "201", } } ], "provider": { "name": "Provider1" } } ``` ### Other related info WIremock version - 1.5.3-ci-16331 (from #784).
adam added the bug label 2025-12-29 15:23:47 +01:00
adam closed this issue 2025-12-29 15:23:47 +01:00
Author
Owner

@StefH commented on GitHub (Aug 12, 2022):

The only possible solution would be that I deserialize the value from the matcher (@"{ ""name"": ""john"" }"), so that the pact could be:

{
   "consumer": {
      "name": "Consumer1"
   },
   "interactions": [
      {
         "providerState": "Example1",
         "request": {
            "method": "POST",
            "path": "/foo",
            "body": {
              "name" : "john"
            }
         },
         "response": {
            "status": "201",
         } 
      }
   ],
   "provider": {
      "name": "Provider1"
   }
}

Another option would be that you can add an example body like:

server
   .Given(Request.Create().UsingPost().WithPath("/foo")
      .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }"))).WithExample( ... todo ...) 
@StefH commented on GitHub (Aug 12, 2022): The only possible solution would be that I deserialize the value from the matcher (`@"{ ""name"": ""john"" }"`), so that the pact could be: ``` json { "consumer": { "name": "Consumer1" }, "interactions": [ { "providerState": "Example1", "request": { "method": "POST", "path": "/foo", "body": { "name" : "john" } }, "response": { "status": "201", } } ], "provider": { "name": "Provider1" } } ``` Another option would be that you can add an example body like: ``` c# server .Given(Request.Create().UsingPost().WithPath("/foo") .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }"))).WithExample( ... todo ...) ```
Author
Owner

@StefH commented on GitHub (Aug 12, 2022):

@shack05
Can you try preview version 1.5.3-ci-16359 ?

@StefH commented on GitHub (Aug 12, 2022): @shack05 Can you try preview version 1.5.3-ci-16359 ?
Author
Owner

@shack05 commented on GitHub (Aug 15, 2022):

Hi @StefH, thank you, preview 1.5.3-ci-16359 works like a charm.

@shack05 commented on GitHub (Aug 15, 2022): Hi @StefH, thank you, preview 1.5.3-ci-16359 works like a charm.
Author
Owner

@StefH commented on GitHub (Aug 15, 2022):

@shack05 Thanks for testing.
For now use the preview, in some time I'll release a new official.

@StefH commented on GitHub (Aug 15, 2022): @shack05 Thanks for testing. For now use the preview, in some time I'll release a new official.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#437