Reset in WireMock admin API not working fine. #225

Closed
opened 2025-12-29 14:25:38 +01:00 by adam · 24 comments
Owner

Originally created by @beloquintana on GitHub (Oct 30, 2019).

Originally assigned to: @StefH on GitHub.

Reset service should reset all mappings, but it delete all stub mappings.

How could I reset mappings via web API ?

Originally created by @beloquintana on GitHub (Oct 30, 2019). Originally assigned to: @StefH on GitHub. Reset service should reset all mappings, but it delete all stub mappings. How could I reset mappings via web API ?
adam added the feature label 2025-12-29 14:25:38 +01:00
adam closed this issue 2025-12-29 14:25:38 +01:00
Author
Owner

@StefH commented on GitHub (Oct 30, 2019):

What do you expect when you reset the mappings?

(Or do you ask this for scenarios?)

@StefH commented on GitHub (Oct 30, 2019): What do you expect when you reset the mappings? (Or do you ask this for scenarios?)
Author
Owner

@beloquintana commented on GitHub (Oct 30, 2019):

When I reset the mappings, I expect that every change in the stub mappings will be applied.

For example to add a new stub mapping, I create the mappings file, then I have to reset my wiremock service to have these changes.

I think that is better to use the Admin API to reset mappings changes that reset the wiremock service.

@beloquintana commented on GitHub (Oct 30, 2019): When I reset the mappings, I expect that every change in the stub mappings will be applied. For example to add a new stub mapping, I create the mappings file, then I have to reset my wiremock service to have these changes. I think that is better to use the Admin API to reset mappings changes that reset the wiremock service.
Author
Owner

@StefH commented on GitHub (Oct 30, 2019):

Not quite sure if I follow, could it be that you want to:

  • create some static mapping json files
  • start wiremock
  • add some more mappings
  • do a reset
  • only the new mappings are deleted. The static mappings which were present during start of wiremock should still be there

?

@StefH commented on GitHub (Oct 30, 2019): Not quite sure if I follow, could it be that you want to: - create some static mapping json files - start wiremock - add some more mappings - do a reset - only the new mappings are deleted. The static mappings which were present during start of wiremock should still be there ?
Author
Owner

@beloquintana commented on GitHub (Oct 30, 2019):

I want to:

  • create some static mapping json files
  • start wiremock
  • add some more mappings in my folder (new mappings are not added in wiremock server)
  • do a reset using Admin API to update wiremock server with the new mappings
  • new mappings and old mapping should be there

The new mappings are not added to wiremock If I do not reset my wiremock service (without using Admin API).

My mapping folder is like:

  • Mappings
    • API1
      • Test1
        • mapping1.json
      • Test2
        • mapping2.json
    • API2
      • Test1
        • mapping1.json
      • Test2
        • mapping2.json
@beloquintana commented on GitHub (Oct 30, 2019): I want to: - create some static mapping json files - start wiremock - add some more mappings in my folder (new mappings are not added in wiremock server) - do a reset using Admin API to update wiremock server with the new mappings - new mappings and old mapping should be there The new mappings are not added to wiremock If I do not reset my wiremock service (without using Admin API). My mapping folder is like: - Mappings - API1 - Test1 - mapping1.json - Test2 - mapping2.json - API2 - Test1 - mapping1.json - Test2 - mapping2.json
Author
Owner

@StefH commented on GitHub (Oct 30, 2019):

Ah I see. I am not sure if the mapping json files are found if these are present in sub folders. Did you try to copy the files directly in the mapping a folder?

@StefH commented on GitHub (Oct 30, 2019): Ah I see. I am not sure if the mapping json files are found if these are present in sub folders. Did you try to copy the files directly in the mapping a folder?
Author
Owner

@beloquintana commented on GitHub (Oct 31, 2019):

The mapping json files are found when I reset the Wiremock server, but not when I call reset from Admin API.

@beloquintana commented on GitHub (Oct 31, 2019): The mapping json files are found when I reset the Wiremock server, but not when I call reset from Admin API.
Author
Owner

@StefH commented on GitHub (Oct 31, 2019):

when I reset the Wiremock server, --> do you mean you just restart the WireMock server?

@StefH commented on GitHub (Oct 31, 2019): `when I reset the Wiremock server,` --> do you mean you just restart the WireMock server?
Author
Owner

@beloquintana commented on GitHub (Oct 31, 2019):

Yes, I also implemented a custom IFileSystemHandler, but the point is how to update the mappings with the new changes without restart the WireMock server.

@beloquintana commented on GitHub (Oct 31, 2019): Yes, I also implemented a custom IFileSystemHandler, but the point is how to update the mappings with the new changes without restart the WireMock server.
Author
Owner

@StefH commented on GitHub (Oct 31, 2019):

  • the EnhancedFileSystemWatcher which is used to detect changes, can only read from the FileSystemHandler.GetMappingFolder() folder. Adding a configuration setting to also read recursive folders could be a solution for your problem

  • Adding a Admin API call like "Refresh" / "RefreshStaticMappings" which calls the FileSystemHandler.EnumerateFiles(...) would also be a solution for your question.

@StefH commented on GitHub (Oct 31, 2019): - the EnhancedFileSystemWatcher which is used to detect changes, can only read from the `FileSystemHandler.GetMappingFolder()` folder. Adding a configuration setting to also read recursive folders could be a solution for your problem - Adding a Admin API call like "Refresh" / "RefreshStaticMappings" which calls the `FileSystemHandler.EnumerateFiles(...)` would also be a solution for your question.
Author
Owner

@beloquintana commented on GitHub (Oct 31, 2019):

Great!!, I think that both solution will be very useful.

@beloquintana commented on GitHub (Oct 31, 2019): Great!!, I think that both solution will be very useful.
Author
Owner

@StefH commented on GitHub (Oct 31, 2019):

I keep this issue open until it's fixed.

@StefH commented on GitHub (Oct 31, 2019): I keep this issue open until it's fixed.
Author
Owner

@StefH commented on GitHub (Oct 31, 2019):

You can try new package from MyGet:
WireMock.Net.1.0.37-ci-12144.nupkg

And set WatchStaticMappingsInSubdirectories to true in the settings.

@StefH commented on GitHub (Oct 31, 2019): You can try new package from MyGet: WireMock.Net.1.0.37-ci-12144.nupkg And set WatchStaticMappingsInSubdirectories to true in the settings.
Author
Owner

@beloquintana commented on GitHub (Nov 1, 2019):

I tested WireMock.Net.1.0.37-ci-12144.nupkg and I find this bug:

New mappings are added, but It never delete the old changes until I restart WireMock server.

Steps to reproduce:

  1. create a static mapping json files with name map1.json
  2. start wiremock
  3. add a mapping in sub folders with name map2.json
    (map2.json is added correctly to wiremock)
  4. edit map2.json

Actual Result:
Wiremock shows 3 mappings:
map1
map2 old version
map2 new version

Expected Result:
Wiremock shows 2 mappings:
map1
map2 new version

@beloquintana commented on GitHub (Nov 1, 2019): I tested WireMock.Net.1.0.37-ci-12144.nupkg and I find this bug: New mappings are added, but It never delete the old changes until I restart WireMock server. Steps to reproduce: 1. create a static mapping json files with name map1.json 2. start wiremock 3. add a mapping in sub folders with name map2.json (map2.json is added correctly to wiremock) 5. edit map2.json Actual Result: Wiremock shows 3 mappings: map1 map2 old version map2 new version Expected Result: Wiremock shows 2 mappings: map1 map2 new version
Author
Owner

@StefH commented on GitHub (Nov 1, 2019):

Question, for step 4; how do you edit map2.json ? Via an editor directly? Or via a PUT on the admin interface?

@StefH commented on GitHub (Nov 1, 2019): Question, for step 4; how do you _edit map2.json_ ? Via an editor directly? Or via a PUT on the admin interface?
Author
Owner

@beloquintana commented on GitHub (Nov 1, 2019):

Via a text editor directly

@beloquintana commented on GitHub (Nov 1, 2019): Via a text editor directly
Author
Owner

@StefH commented on GitHub (Nov 1, 2019):

This is a different thing.

If you just have a mapping file named map1.json, and this file does not define the Guid property, a new mapping is added when you edit this file in an editor.

There are 2 solutions for this:

  1. Rename the file to 791a3f31-6946-4ce7-8e6f-0237c7443275.json
  2. Define the Guid in the mapping json like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.NETCoreApp2/__admin/mappings/791a3f31-6946-4ce7-8e6f-0237c7443275.json#L2
@StefH commented on GitHub (Nov 1, 2019): This is a different thing. If you just have a mapping file named `map1.json`, and this file does not define the Guid property, a new mapping is added when you edit this file in an editor. There are 2 solutions for this: 1. Rename the file to `791a3f31-6946-4ce7-8e6f-0237c7443275.json` 2. Define the Guid in the mapping json like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.NETCoreApp2/__admin/mappings/791a3f31-6946-4ce7-8e6f-0237c7443275.json#L2
Author
Owner

@StefH commented on GitHub (Nov 1, 2019):

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

@StefH commented on GitHub (Nov 1, 2019): https://github.com/WireMock-Net/WireMock.Net/pull/374
Author
Owner

@beloquintana commented on GitHub (Nov 1, 2019):

Thanks for the WatchStaticMappingsInSubdirectories.

I think that define a Guid in a text editor is tricky and it is not intuitive.
If we could define an Id without any restriccion (Example: string id) would be easy to add and edit mapping json files via text editor.

Would it be possible to do?

@beloquintana commented on GitHub (Nov 1, 2019): Thanks for the WatchStaticMappingsInSubdirectories. I think that define a Guid in a text editor is tricky and it is not intuitive. If we could define an Id without any restriccion (Example: string id) would be easy to add and edit mapping json files via text editor. Would it be possible to do?
Author
Owner

@StefH commented on GitHub (Nov 1, 2019):

Sorry. The internal logic is using these guids.

Normally when adding a mapping via the admin API, the guid is assigned and stored in the mapping file when it's saved. Also when proxying, the guide is defined.

@StefH commented on GitHub (Nov 1, 2019): Sorry. The internal logic is using these guids. Normally when adding a mapping via the admin API, the guid is assigned and stored in the mapping file when it's saved. Also when proxying, the guide is defined.
Author
Owner

@StefH commented on GitHub (Nov 2, 2019):

I've also added an extra parameter to the Reset API method:

ResetMappingsAsync(bool? reloadStaticMappings = false);

POST example = to http://{{wm_hostname}}/__admin/mappings/reset?reloadStaticMappings=true

Which will reload the static mappings after a reset (=delete) from the mappings.

A preview NuGet can be found at MyGet --> WireMock.Net.1.0.37-ci-12153.nupkg

@StefH commented on GitHub (Nov 2, 2019): I've also added an extra parameter to the `Reset` API method: ``` c# ResetMappingsAsync(bool? reloadStaticMappings = false); ``` POST example = to `http://{{wm_hostname}}/__admin/mappings/reset?reloadStaticMappings=true` Which will reload the static mappings after a reset (=delete) from the mappings. A preview NuGet can be found at MyGet --> WireMock.Net.1.0.37-ci-12153.nupkg
Author
Owner

@StefH commented on GitHub (Nov 5, 2019):

Is this ok?

@StefH commented on GitHub (Nov 5, 2019): Is this ok?
Author
Owner

@beloquintana commented on GitHub (Nov 6, 2019):

This change is only for WireMock.Net.StandAlone?

WireMock.Net.1.0.37-ci-12153.nupkg is the StandAlone

@beloquintana commented on GitHub (Nov 6, 2019): This change is only for WireMock.Net.StandAlone? WireMock.Net.1.0.37-ci-12153.nupkg is the StandAlone
Author
Owner

@StefH commented on GitHub (Nov 6, 2019):

Both nuget packages should be there with that 1.0.37-ci-12153 identifier.

In your case, for testing you can use either package.

@StefH commented on GitHub (Nov 6, 2019): Both nuget packages should be there with that 1.0.37-ci-12153 identifier. In your case, for testing you can use either package.
Author
Owner

@beloquintana commented on GitHub (Nov 7, 2019):

It is work very well! I will use this functionality a lot.
Thanks you!!!

@beloquintana commented on GitHub (Nov 7, 2019): It is work very well! I will use this functionality a lot. Thanks you!!!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#225