WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.39k stars 207 forks source link

422 Unprocessable Entity #1061

Closed chertby closed 8 months ago

chertby commented 8 months ago

I run a WireMock in docker and then use WireMock.Net.RestClient to create the mappings.

mappingBuilder.Given(m => m
    .WithTitle("This is my title 1")
    .WithRequest(req => req
        .UsingGet()
        .WithPath("/bla1")
    )
    .WithResponse(rsp => rsp
        .WithBody("x1")
        .WithHeaders(h => h.Add("h1", "v1"))
        .WithStatusCode(StatusCodes.Status200OK)
    )
);

await mappingBuilder.BuildAndPostAsync(cancellationToken);

I get an error:

{
  "errors" : [ {
    "code" : 10,
    "source" : {
      "pointer" : "/"
    },
    "title" : "Error parsing JSON",
    "detail" : "Cannot deserialize value of type `com.github.tomakehurst.wiremock.stubbing.StubMapping` from Array value (token `JsonToken.START_ARRAY`)"
  } ]
}

The client allows to send a collection of mappings

/// <summary>
/// Add new mappings.
/// </summary>
/// <param name="mappings">MappingModels</param>
/// <param name="cancellationToken">The optional cancellationToken.</param>
[Post("mappings")]
[Header("Content-Type", "application/json")]
Task<StatusModel> PostMappingsAsync([Body] IList<MappingModel> mappings, CancellationToken cancellationToken = default);

But if believe the specification, then there is no such endpoint.

I can't figure it out, am I doing something wrong?

chertby commented 8 months ago

Oh, it was my mistake I used the basic image wiremock/wiremock instead of sheyenrath/wiremock.net.

StefH commented 8 months ago

Correct.

If you want to use a RestClient to access the WireMock Java version, you can try WireMock.Org.RestClient.