How to enable AppendGuidToSavedMappingFile when proxying multiple endpoints? #620

Open
opened 2025-12-29 15:29:02 +01:00 by adam · 4 comments
Owner

Originally created by @SergVro on GitHub (Jul 29, 2024).

Originally assigned to: @StefH on GitHub.

I have a setup where I have a range of static mapping files for multiple endpoints. I also have proxy configuration for multiple services with lower priority to intercept the calls not matched by static mapping. My goal is to have a setup where calls not matched with static mapping files, are proxied to original service and a new mapping file for that call is stored under __admin/mappings. This kind of works, but files get overwritten if similar requests are issued. I found the AppendGuidToSavedMappingFile setting, but it does not seem to work in a "local" proxy configs like:

          server.Given(Request.Create().WithPath("/auth/token"))
            .AtPriority(1000)
            .RespondWith(
                Response.Create()
                    .WithProxy(
                        new ProxyAndRecordSettings
                        {
                            Url = "https://auto-generate-jwt.stg.se",
                            SaveMapping = true,
                            SaveMappingToFile = true,
                            AppendGuidToSavedMappingFile = true, // <-- this does not give any effect
                        }
                    )
            );

        server.Given(Request.Create().WithPath("/api/keys"))
            .AtPriority(1000)
            .RespondWith(
                Response.Create()
                    .WithProxy(
                        new ProxyAndRecordSettings
                        {
                            Url = "https://jwks.dev.se",
                            SaveMapping = true,
                            SaveMappingToFile = true,
                            AppendGuidToSavedMappingFile = true, // <-- this does not give any effect
                        })
            );

I tried the AppendGuidToSavedMappingFile with a "global" proxy config in WireMockServerSettings.ProxyAndRecordSettings and then it works, but that requires specifying proxy Url which overrides the proxy Url specified in the mapping configuration. Any tips on how to achieve proxying to multiple URLs plus AppendGuidToSavedMappingFile?

Originally created by @SergVro on GitHub (Jul 29, 2024). Originally assigned to: @StefH on GitHub. I have a setup where I have a range of static mapping files for multiple endpoints. I also have proxy configuration for multiple services with lower priority to intercept the calls not matched by static mapping. My goal is to have a setup where calls not matched with static mapping files, are proxied to original service and a new mapping file for that call is stored under __admin/mappings. This kind of works, but files get overwritten if similar requests are issued. I found the `AppendGuidToSavedMappingFile` setting, but it does not seem to work in a "local" proxy configs like: ```cs server.Given(Request.Create().WithPath("/auth/token")) .AtPriority(1000) .RespondWith( Response.Create() .WithProxy( new ProxyAndRecordSettings { Url = "https://auto-generate-jwt.stg.se", SaveMapping = true, SaveMappingToFile = true, AppendGuidToSavedMappingFile = true, // <-- this does not give any effect } ) ); server.Given(Request.Create().WithPath("/api/keys")) .AtPriority(1000) .RespondWith( Response.Create() .WithProxy( new ProxyAndRecordSettings { Url = "https://jwks.dev.se", SaveMapping = true, SaveMappingToFile = true, AppendGuidToSavedMappingFile = true, // <-- this does not give any effect }) ); ``` I tried the `AppendGuidToSavedMappingFile` with a "global" proxy config in WireMockServerSettings.ProxyAndRecordSettings and then it works, but that requires specifying proxy `Url` which overrides the proxy `Url` specified in the mapping configuration. Any tips on how to achieve proxying to multiple URLs plus `AppendGuidToSavedMappingFile`?
adam added the question label 2025-12-29 15:29:02 +01:00
Author
Owner

@StefH commented on GitHub (Jul 29, 2024):

Can you confirm that the files are saved when using local proxy?

@StefH commented on GitHub (Jul 29, 2024): Can you confirm that the files are saved when using local proxy?
Author
Owner

@SergVro commented on GitHub (Jul 30, 2024):

Can you confirm that the files are saved when using local proxy?

Yes, new mapping files are created. Both SaveMapping and SaveMappingToFile are respected when set in the .WithProxy call.

@SergVro commented on GitHub (Jul 30, 2024): > Can you confirm that the files are saved when using local proxy? Yes, new mapping files are created. Both `SaveMapping` and `SaveMappingToFile` are respected when set in the `.WithProxy` call.
Author
Owner

@LazyPotato commented on GitHub (Apr 23, 2025):

Hello, I have the same issue - mapping files are created without guids and hence are overwritten on succeeding requests. Any news on this?
Thanks in advance

@LazyPotato commented on GitHub (Apr 23, 2025): Hello, I have the same issue - mapping files are created without guids and hence are overwritten on succeeding requests. Any news on this? Thanks in advance
Author
Owner

@DouglasDev commented on GitHub (Jun 2, 2025):

The AppendGuidToSavedMappingFile setting only works when used with the global ProxyAndRecordSettings on WireMockServerSettings, not when used in local .WithProxy(...) calls per mapping. This is why you're seeing the GUID appended only when using the global proxy config, and not with per-mapping proxies.

Currently, WireMock.Net does not support AppendGuidToSavedMappingFile for individual proxy mappings. If you need to proxy multiple services and avoid mapping file overwrites, an alternative approach is:

Start a separate WireMock server instance for each upstream service, each with its own global ProxyAndRecordSettings, including AppendGuidToSavedMappingFile = true and the appropriate Url.

Or, use unique PrefixForSavedMappingFile and a dedicated FileSystemHandler/directory per upstream.

Example:

var server1 = WireMockServer.Start(new WireMockServerSettings
{
    Port = 9001, // choose a unique port for each server
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        Url = "https://service1.example.com",
        SaveMapping = true,
        SaveMappingToFile = true,
        AppendGuidToSavedMappingFile = true
    },
    FileSystemHandler = new LocalFileSystemHandler("./Recordings/service1"),
});

var server2 = WireMockServer.Start(new WireMockServerSettings
{
    Port = 9002,
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        Url = "https://service2.example.com",
        SaveMapping = true,
        SaveMappingToFile = true,
        AppendGuidToSavedMappingFile = true
    },
    FileSystemHandler = new LocalFileSystemHandler("./Recordings/service2"),
});
@DouglasDev commented on GitHub (Jun 2, 2025): The AppendGuidToSavedMappingFile setting only works when used with the global ProxyAndRecordSettings on WireMockServerSettings, not when used in local .WithProxy(...) calls per mapping. This is why you're seeing the GUID appended only when using the global proxy config, and not with per-mapping proxies. Currently, WireMock.Net does not support AppendGuidToSavedMappingFile for individual proxy mappings. If you need to proxy multiple services and avoid mapping file overwrites, an alternative approach is: Start a separate WireMock server instance for each upstream service, each with its own global ProxyAndRecordSettings, including AppendGuidToSavedMappingFile = true and the appropriate Url. Or, use unique PrefixForSavedMappingFile and a dedicated FileSystemHandler/directory per upstream. Example: ```c# var server1 = WireMockServer.Start(new WireMockServerSettings { Port = 9001, // choose a unique port for each server ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "https://service1.example.com", SaveMapping = true, SaveMappingToFile = true, AppendGuidToSavedMappingFile = true }, FileSystemHandler = new LocalFileSystemHandler("./Recordings/service1"), }); var server2 = WireMockServer.Start(new WireMockServerSettings { Port = 9002, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "https://service2.example.com", SaveMapping = true, SaveMappingToFile = true, AppendGuidToSavedMappingFile = true }, FileSystemHandler = new LocalFileSystemHandler("./Recordings/service2"), }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#620