Skip to content
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

Response body is missing in generated pact file when IBodyResponseBuilder.WithBody is used #784

Closed
shack05 opened this issue Aug 10, 2022 · 4 comments
Labels

Comments

@shack05
Copy link

shack05 commented Aug 10, 2022

Describe the bug

If I use the IBodyResponseBuilder.WithBody method to specify a response based on a string and then generate a pact file then the pact file will not include the response body.
If I use WithBodyAsJson the response body is defined as expected in the pact file.

Expected behavior:

The response body is defined in the pact file.

Test to reproduce

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

server
   .Given(Request.Create().WithPath("/foo").UsingGet())
   .WithTitle("Example1")
   .RespondWith(Response.Create()
      .WithStatusCode(200)
      .WithBody(@"{ foo: ""bar"" }"));

server.SavePact("...")

Expected pact:

{
   "consumer": {
      "name": "Consumer1"
   },
   "interactions": [
      {
         "providerState": "Example1",
         "request": {
            "method": "GET",
            "path": "/foo",
         },
         "response": {
            "body": {
               "foo": "bar"
            },
            "status": "200",
         } 
      }
   ],
   "provider": {
      "name": "Provider1"
   }
}

Actual pact:
The resulting pact file is:

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

Other related info

Wiremock version 1.5.3

The reason I am using WithBody rather than WithBodyAsJson is because, as far as I am aware, the json I am trying to describe cannot be declared as an anonymous object because some json property names start with a dollar sign and some property names include colons. Is there an alternative to using WithBody such as being able to configure a json serializer to be used in the WithBodyAsJson method?

@shack05 shack05 added the bug label Aug 10, 2022
@StefH
Copy link
Collaborator

StefH commented Aug 10, 2022

Hello @shack05

I'll take a look at the code.


For this question:

. Is there an alternative to using WithBody such as being able to configure a json serializer to be used in the WithBodyAsJson method?

--> This looks a bit like this one? #774

@StefH
Copy link
Collaborator

StefH commented Aug 10, 2022

@shack05
Can you try preview version 1.5.3-ci-16331 from MyGet?

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@shack05
Copy link
Author

shack05 commented Aug 11, 2022

Hi,
Thanks for the quick response.

--> This looks a bit like this one? #774
Yes, although with the change you've made in the preview version I no longer have a use case for a separate serializer.

Can you try preview version 1.5.3-ci-16331 from MyGet?
Thanks, I can confirm the response is as expected for that preview version.
I did notice however that the request body is not defined in the pact file if I create a body.
I was using a JsonPartialMatcher to define the constraints for the body.
Are request bodies supported?

@StefH
Copy link
Collaborator

StefH commented Aug 11, 2022

@shack05

Can you open a new issue for this:

I did notice however that the request body is not defined in the pact file if I create a body.
I was using a JsonPartialMatcher to define the constraints for the body.

I'll merge the PR. For now just keep using the preview version, in some time a new official version will be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants