Admin API fails to create a mapping with Request Body matching #281

Closed
opened 2025-12-29 08:25:19 +01:00 by adam · 5 comments
Owner

Originally created by @yunj on GitHub (Jul 9, 2020).

Describe the bug

Admin API is used to create a mapping which has some sort of request body match, but other matches get created except body.

Expected behavior:

Body match should appear when querying GET __admin/mappings.

Test to reproduce

Admin API is used to create the following mapping.

var model = new MappingModel
{
    Request = new RequestModel
    {
        Path = "test",
        Body = new BodyModel
        {
            Matcher = new MatcherModel
            {
                Name = "RegexMatcher",
                Pattern = "hello"
            }
        }
    },
    Response = new ResponseModel
    {
        Body = "world"
    }
};
await RestClient.For<IWireMockAdminApi>("http://localhost").PostMappingAsync(model);

The response from GET __admin/mappings

[
  {
    "Guid": "486b7f76-f29a-4928-9f16-bf6c3a2ce8f2",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "test",
            "IgnoreCase": false
          }
        ]
      }
    },
    "Response": {
      "Body": "world"
    }
  }
]
Originally created by @yunj on GitHub (Jul 9, 2020). ### Describe the bug Admin API is used to create a mapping which has some sort of request body match, but other matches get created except body. ### Expected behavior: Body match should appear when querying `GET __admin/mappings`. ### Test to reproduce Admin API is used to create the following mapping. ``` c# var model = new MappingModel { Request = new RequestModel { Path = "test", Body = new BodyModel { Matcher = new MatcherModel { Name = "RegexMatcher", Pattern = "hello" } } }, Response = new ResponseModel { Body = "world" } }; await RestClient.For<IWireMockAdminApi>("http://localhost").PostMappingAsync(model); ``` The response from `GET __admin/mappings` ``` json [ { "Guid": "486b7f76-f29a-4928-9f16-bf6c3a2ce8f2", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "test", "IgnoreCase": false } ] } }, "Response": { "Body": "world" } } ] ```
adam added the bug label 2025-12-29 08:25:19 +01:00
adam closed this issue 2025-12-29 08:25:19 +01:00
Author
Owner

@StefH commented on GitHub (Jul 9, 2020):

Thank you.
I'll investigate.

@StefH commented on GitHub (Jul 9, 2020): Thank you. I'll investigate.
Author
Owner

@StefH commented on GitHub (Jul 9, 2020):

@yunj
The root cause is that you don't provide the Methods on you wish to match. The current code does not return the bodymatcher if there are no Methods defined or if the methods have a 'get'.

I'll investigate why I did add this check in the code.

For your solution now: set the Methods.

@StefH commented on GitHub (Jul 9, 2020): @yunj The root cause is that you don't provide the Methods on you wish to match. The current code does not return the bodymatcher if there are no Methods defined or if the methods have a 'get'. I'll investigate why I did add this check in the code. For your solution now: set the Methods.
Author
Owner

@StefH commented on GitHub (Jul 9, 2020):

https://github.com/WireMock-Net/WireMock.Net/pull/487

@StefH commented on GitHub (Jul 9, 2020): https://github.com/WireMock-Net/WireMock.Net/pull/487
Author
Owner

@StefH commented on GitHub (Jul 9, 2020):

Fixed.
New NuGet and Docker will be released soon.

@StefH commented on GitHub (Jul 9, 2020): Fixed. New NuGet and Docker will be released soon.
Author
Owner

@yunj commented on GitHub (Jul 9, 2020):

@StefH thanks very much for your quick fix.

@yunj commented on GitHub (Jul 9, 2020): @StefH thanks very much for your quick fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#281