MappingsToCSharpCode should use RegexMatcher when specified #621

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

Originally created by @carlin-q-scott on GitHub (Aug 5, 2024).

Originally assigned to: @StefH on GitHub.

Is your feature request related to a problem? Please describe.
I used the MappingsToCSharpCode on the WiremockServer class to get C# mappings for my json mocks and it did not respect the matchers. It assumed everything was an exact match.

My json defined mock:

{
  "Request": {
    "Methods": [
      "POST"
    ],
    "Path": "/auth",
    "Params": [
      {
        "Name": "clientId",
        "Matchers": [
          {
            "Name": "RegexMatcher",
            "Pattern": "^scenario_(.+)$"
          }
        ]
      }
    ]
  }
}

The resulting CSharpCode:

builder
    .Given(Request.Create()
        .UsingMethod("POST")
        .WithPath("/auth")
        .WithParam("clientId", $"^scenario_(.+)$")
    )

Describe the solution you'd like
If the Matcher.Name is RegexMatcher, then create a RegexMatcher instead of directly passing the pattern to the RequestBuilder method.

builder
    .Given(Request.Create()
        .UsingMethod("POST")
        .WithPath("/auth")
        .WithParam("clientId", new RegexMatcher($"^scenario_(.+)$"))
    )

Describe alternatives you've considered
Manually fixing the generated code.

Is your feature request supported by WireMock (java version)? Please provide details.
I don't think this relevant.

Additional context
Add any other context or screenshots about the feature request here.

Originally created by @carlin-q-scott on GitHub (Aug 5, 2024). Originally assigned to: @StefH on GitHub. **Is your feature request related to a problem? Please describe.** I used the MappingsToCSharpCode on the WiremockServer class to get C# mappings for my json mocks and it did not respect the matchers. It assumed everything was an exact match. My json defined mock: ```json { "Request": { "Methods": [ "POST" ], "Path": "/auth", "Params": [ { "Name": "clientId", "Matchers": [ { "Name": "RegexMatcher", "Pattern": "^scenario_(.+)$" } ] } ] } } ``` The resulting CSharpCode: ```c# builder .Given(Request.Create() .UsingMethod("POST") .WithPath("/auth") .WithParam("clientId", $"^scenario_(.+)$") ) ``` **Describe the solution you'd like** If the Matcher.Name is RegexMatcher, then create a RegexMatcher instead of directly passing the pattern to the RequestBuilder method. ```c# builder .Given(Request.Create() .UsingMethod("POST") .WithPath("/auth") .WithParam("clientId", new RegexMatcher($"^scenario_(.+)$")) ) ``` **Describe alternatives you've considered** Manually fixing the generated code. **Is your feature request supported by [WireMock (java version)](https://www.wiremock.org)? Please provide details.** I don't think this relevant. **Additional context** Add any other context or screenshots about the feature request here.
adam added the bug label 2025-12-29 08:31:19 +01:00
adam closed this issue 2025-12-29 08:31:19 +01:00
Author
Owner

@StefH commented on GitHub (Aug 5, 2024):

@carlin-q-scott
This is indeed invalid.
(ExactMatcher and LinqMatcher are also not correctly transformed)

However fixing this needs a complete rewrite from the generating logic...
(Currently the logic is defined in 1 class, but the knowledge about the parameters should be moved to the matcher itself...)

@StefH commented on GitHub (Aug 5, 2024): @carlin-q-scott This is indeed invalid. (ExactMatcher and LinqMatcher are also not correctly transformed) However fixing this needs a complete rewrite from the generating logic... (Currently the logic is defined in 1 class, but the knowledge about the parameters should be moved to the matcher itself...)
Author
Owner

@StefH commented on GitHub (Aug 6, 2024):

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

@StefH commented on GitHub (Aug 6, 2024): https://github.com/WireMock-Net/WireMock.Net/pull/1152
Author
Owner

@StefH commented on GitHub (Aug 6, 2024):

@carlin-q-scott
If you want, you can use preview 1.5.62-ci-19075 to test.

@StefH commented on GitHub (Aug 6, 2024): @carlin-q-scott If you want, you can use preview 1.5.62-ci-19075 to test.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#621