How to submit mappings for multiple request, responses #158

Closed
opened 2025-12-29 14:23:53 +01:00 by adam · 13 comments
Owner

Originally created by @arpymastro on GitHub (Dec 14, 2018).

I have a .net core console app which launches a mock server(using WireMock.StandAlone and WireMock.Net nuget package) within a console app as -

static void Main(string[] args)
    {
        // see source code for all the possible properties
        var settings = new FluentMockServerSettings
            {
                AllowPartialMapping=true,
                StartAdminInterface=true
            };
        StandAloneApp.Start(settings);

        Console.WriteLine("Press any key to stop the server");
        Console.ReadKey();
    }

Now I want to create stub mappings for my multiple request, responses and so I'm posting json data to http://localhost:5001/__admin/mappings -

[
	{
		"Request" : {....},
		"Response" : {....}
	},
	{
		"Request" : {....},
		"Response" : {....}
	},
	{
		"Request" : {....},
		"Response" : {....}
	}
]

But it is showing - System.InvalidCastException Unable to cast object of type Newtonsoft.Json.Linq.JArray to type Newtonsoft.Json.Linq.JObject.

If I try to create mapping for one request, response it creates successfully.

Originally created by @arpymastro on GitHub (Dec 14, 2018). I have a .net core console app which launches a mock server(using WireMock.StandAlone and WireMock.Net nuget package) within a console app as - ``` c# static void Main(string[] args) { // see source code for all the possible properties var settings = new FluentMockServerSettings { AllowPartialMapping=true, StartAdminInterface=true }; StandAloneApp.Start(settings); Console.WriteLine("Press any key to stop the server"); Console.ReadKey(); } ``` Now I want to create stub mappings for my multiple request, responses and so I'm posting json data to http://localhost:5001/__admin/mappings - ``` js [ { "Request" : {....}, "Response" : {....} }, { "Request" : {....}, "Response" : {....} }, { "Request" : {....}, "Response" : {....} } ] ``` But it is showing - **System.InvalidCastException Unable to cast object of type Newtonsoft.Json.Linq.JArray to type Newtonsoft.Json.Linq.JObject.** If I try to create mapping for one request, response it creates successfully.
adam added the feature label 2025-12-29 14:23:53 +01:00
adam closed this issue 2025-12-29 14:23:53 +01:00
Author
Owner

@StefH commented on GitHub (Dec 14, 2018):

This is not yet supported, but this looks like a good idea. I'll investigate and keep you informed on the progress.

@StefH commented on GitHub (Dec 14, 2018): This is not yet supported, but this looks like a good idea. I'll investigate and keep you informed on the progress.
Author
Owner

@arpymastro commented on GitHub (Dec 14, 2018):

@StefH
Thanks.
Till then do I need to post the mappings separately?

Also, how can I pre-load the mappings by using .json file? I don't have __admin/mappings path in my project as I am using WireMock.Net nuget package. I also want to know how I can read and create stubs from the pre-loaded json file.

@arpymastro commented on GitHub (Dec 14, 2018): @StefH Thanks. Till then do I need to post the mappings separately? Also, how can I pre-load the mappings by using .json file? I don't have __admin/mappings path in my project as I am using WireMock.Net nuget package. I also want to know how I can read and create stubs from the pre-loaded json file.
Author
Owner

@StefH commented on GitHub (Dec 14, 2018):

  1. Yes, post them separate.

  2. You can just create this folder __admin/mappings manually. See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.NETCoreApp2

The json files here are just the same as the body you normally post to the http://localhost:5001/__admin/mappings URL.

When you have posted a few mappings to the server, you can execute a POST request https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#post-__adminmappingssave
to save the mappings to the __admin/mappings folder.

And if needed, you are allowed to rename the files as you like.

@StefH commented on GitHub (Dec 14, 2018): 1. Yes, post them separate. 2. You can just create this folder `__admin/mappings` manually. See https://github.com/WireMock-Net/WireMock.Net/tree/master/examples/WireMock.Net.Console.NETCoreApp2 The json files here are just the same as the body you normally post to the http://localhost:5001/__admin/mappings URL. When you have posted a few mappings to the server, you can execute a POST request https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference#post-__adminmappingssave to save the mappings to the `__admin/mappings` folder. And if needed, you are allowed to rename the files as you like.
Author
Owner

@arpymastro commented on GitHub (Dec 14, 2018):

@StefH - Can you please help me understand how to post the mappings to the server?
I have created __admin/mappings folder manually and have added two json files(mystub_get.json and mystub_post.json) in it.

I am doing a post @ http://localhost:5001/__admin/mappings/mystub_get.json but it is responding with StatusCode:404 No matching mapping found.

I am not putting any request body while posting the mappings to the server. Do I have to? How? I am not getting what I am doing wrong.

@arpymastro commented on GitHub (Dec 14, 2018): @StefH - Can you please help me understand how to post the mappings to the server? I have created `__admin/mappings` folder manually and have added two json files(mystub_get.json and mystub_post.json) in it. I am doing a post @ http://localhost:5001/__admin/mappings/mystub_get.json but it is responding with `StatusCode:404 No matching mapping found.` I am not putting any request body while posting the mappings to the server. Do I have to? How? I am not getting what I am doing wrong.
Author
Owner

@arpymastro commented on GitHub (Dec 14, 2018):

Ignore my comment. I figured out. I needed to set property in my .csproj to copy the .json files into my bin folder. Works now! :)

@arpymastro commented on GitHub (Dec 14, 2018): Ignore my comment. I figured out. I needed to set property in my .csproj to copy the .json files into my bin folder. Works now! :)
Author
Owner

@StefH commented on GitHub (Dec 14, 2018):

Cool.

@StefH commented on GitHub (Dec 14, 2018): Cool.
Author
Owner

@StefH commented on GitHub (Dec 15, 2018):

New NuGet version 1.0.6 will be released in some time which implements posting multiple mappings as an array.

@StefH commented on GitHub (Dec 15, 2018): New NuGet version 1.0.6 will be released in some time which implements posting multiple mappings as an array.
Author
Owner

@arpymastro commented on GitHub (Dec 20, 2018):

@StefH - I tested NuGet version 1.0.6 for multiple mappings. It works fine when I POST an array to http://localhost:5001/__admin/mappings.
Thank you!

But, if I have the array in an .json file kept under __admin/mappings/myJsonArray.json then it doesn't work. Will this be implemented in near future?

@arpymastro commented on GitHub (Dec 20, 2018): @StefH - I tested NuGet version 1.0.6 for multiple mappings. It works fine when I POST an array to http://localhost:5001/__admin/mappings. Thank you! But, if I have the array in an .json file kept under `__admin/mappings/myJsonArray.json` then it doesn't work. Will this be implemented in near future?
Author
Owner

@StefH commented on GitHub (Dec 20, 2018):

I forgot to implement that array logic, I 'll create a new NuGet in some time.

Just watch this issue.

@StefH commented on GitHub (Dec 20, 2018): I forgot to implement that array logic, I 'll create a new NuGet in some time. Just watch this issue.
Author
Owner

@StefH commented on GitHub (Dec 20, 2018):

If you have time, you can test NuGet version 1.0.7-ci-1630 (from MyGet) which fixes reading an array.

@StefH commented on GitHub (Dec 20, 2018): If you have time, you can test NuGet version `1.0.7-ci-1630` (from MyGet) which fixes reading an array.
Author
Owner

@arpymastro commented on GitHub (Dec 21, 2018):

@StefH
I will test this and will let you know.

@arpymastro commented on GitHub (Dec 21, 2018): @StefH I will test this and will let you know.
Author
Owner

@StefH commented on GitHub (Jan 9, 2019):

@arpymastro Did youhave time to test this ?

@StefH commented on GitHub (Jan 9, 2019): @arpymastro Did youhave time to test this ?
Author
Owner

@StefH commented on GitHub (Jan 19, 2019):

New NuGet will be released shortly.

@StefH commented on GitHub (Jan 19, 2019): New NuGet will be released shortly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#158