diff --git a/WireMock.Net Solution.sln.DotSettings b/WireMock.Net Solution.sln.DotSettings
index 99ef6d87..92eaabab 100644
--- a/WireMock.Net Solution.sln.DotSettings
+++ b/WireMock.Net Solution.sln.DotSettings
@@ -33,6 +33,7 @@
True
True
True
+ True
True
True
True
diff --git a/src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs b/src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs
index cc70e57f..3f8cb318 100644
--- a/src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs
+++ b/src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs
@@ -1,36 +1,25 @@
-using System;
+namespace WireMock.Types;
-namespace WireMock.Types
+///
+/// Logic to use when replace a JSON node using the Transformer.
+///
+public enum ReplaceNodeOptions
{
///
- /// Flags to use when replace a JSON node using the Transformer.
+ /// Try to evaluate a templated value.
+ /// In case this is valid, return the value and if the value can be converted to a primitive type, use that value.
///
- [Flags]
- public enum ReplaceNodeOptions
- {
- ///
- /// Default
- ///
- None = 0
+ EvaluateAndTryToConvert = 0,
- /////
- ///// Replace boolean string value to a real boolean value. (This is used by default to maintain backward compatibility.)
- /////
- //Bool = 0b00000001,
+ ///
+ /// Try to evaluate a templated value.
+ /// In case this is valid, return the value, else fallback to the parse behavior.
+ ///
+ Evaluate = 1,
- /////
- ///// Replace integer string value to a real integer value.
- /////
- //Integer = 0b00000010,
-
- /////
- ///// Replace long string value to a real long value.
- /////
- //Long = 0b00000100,
-
- /////
- ///// Replace all string values to a real values.
- /////
- //All = Bool | Integer | Long
- }
+ ///
+ /// Parse templated string to a templated string.
+ /// (keep a templated string value as string value).
+ ///
+ Parse = 2
}
\ No newline at end of file
diff --git a/src/WireMock.Net.Abstractions/Types/TransformerType.cs b/src/WireMock.Net.Abstractions/Types/TransformerType.cs
index 5d7015e1..9ae26df9 100644
--- a/src/WireMock.Net.Abstractions/Types/TransformerType.cs
+++ b/src/WireMock.Net.Abstractions/Types/TransformerType.cs
@@ -1,23 +1,22 @@
-namespace WireMock.Types
+namespace WireMock.Types;
+
+///
+/// The ResponseMessage Transformers
+///
+public enum TransformerType
{
///
- /// The ResponseMessage Transformers
+ /// https://github.com/Handlebars-Net/Handlebars.Net
///
- public enum TransformerType
- {
- ///
- /// https://github.com/Handlebars-Net/Handlebars.Net
- ///
- Handlebars,
+ Handlebars,
- ///
- /// https://github.com/scriban/scriban : default
- ///
- Scriban,
+ ///
+ /// https://github.com/scriban/scriban : default
+ ///
+ Scriban,
- ///
- /// https://github.com/scriban/scriban : DotLiquid
- ///
- ScribanDotLiquid
- }
+ ///
+ /// https://github.com/scriban/scriban : DotLiquid
+ ///
+ ScribanDotLiquid
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Http/WebhookSender.cs b/src/WireMock.Net/Http/WebhookSender.cs
index 63b4fd6d..25aaebe5 100644
--- a/src/WireMock.Net/Http/WebhookSender.cs
+++ b/src/WireMock.Net/Http/WebhookSender.cs
@@ -51,14 +51,14 @@ internal class WebhookSender
switch (webhookRequest.TransformerType)
{
case TransformerType.Handlebars:
- var factoryHandlebars = new HandlebarsContextFactory(_settings.FileSystemHandler, _settings.HandlebarsRegistrationCallback);
- transformer = new Transformer(factoryHandlebars);
+ var factoryHandlebars = new HandlebarsContextFactory(_settings);
+ transformer = new Transformer(_settings, factoryHandlebars);
break;
case TransformerType.Scriban:
case TransformerType.ScribanDotLiquid:
var factoryDotLiquid = new ScribanContextFactory(_settings.FileSystemHandler, webhookRequest.TransformerType);
- transformer = new Transformer(factoryDotLiquid);
+ transformer = new Transformer(_settings, factoryDotLiquid);
break;
default:
diff --git a/src/WireMock.Net/ResponseBuilders/ITransformResponseBuilder.cs b/src/WireMock.Net/ResponseBuilders/ITransformResponseBuilder.cs
index a9da2312..729f8894 100644
--- a/src/WireMock.Net/ResponseBuilders/ITransformResponseBuilder.cs
+++ b/src/WireMock.Net/ResponseBuilders/ITransformResponseBuilder.cs
@@ -29,5 +29,5 @@ public interface ITransformResponseBuilder : IDelayResponseBuilder
///
/// The .
///
- IResponseBuilder WithTransformer(TransformerType transformerType = TransformerType.Handlebars, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.None);
+ IResponseBuilder WithTransformer(TransformerType transformerType = TransformerType.Handlebars, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.Evaluate);
}
\ No newline at end of file
diff --git a/src/WireMock.Net/ResponseBuilders/Response.cs b/src/WireMock.Net/ResponseBuilders/Response.cs
index 23221f8a..13c482b4 100644
--- a/src/WireMock.Net/ResponseBuilders/Response.cs
+++ b/src/WireMock.Net/ResponseBuilders/Response.cs
@@ -207,7 +207,7 @@ public partial class Response : IResponseBuilder
}
///
- public IResponseBuilder WithTransformer(TransformerType transformerType, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.None)
+ public IResponseBuilder WithTransformer(TransformerType transformerType, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.Evaluate)
{
UseTransformer = true;
TransformerType = transformerType;
@@ -314,14 +314,14 @@ public partial class Response : IResponseBuilder
switch (TransformerType)
{
case TransformerType.Handlebars:
- var factoryHandlebars = new HandlebarsContextFactory(settings.FileSystemHandler, settings.HandlebarsRegistrationCallback);
- responseMessageTransformer = new Transformer(factoryHandlebars);
+ var factoryHandlebars = new HandlebarsContextFactory(settings);
+ responseMessageTransformer = new Transformer(settings, factoryHandlebars);
break;
case TransformerType.Scriban:
case TransformerType.ScribanDotLiquid:
var factoryDotLiquid = new ScribanContextFactory(settings.FileSystemHandler, TransformerType);
- responseMessageTransformer = new Transformer(factoryDotLiquid);
+ responseMessageTransformer = new Transformer(settings, factoryDotLiquid);
break;
default:
diff --git a/src/WireMock.Net/Serialization/WebhookMapper.cs b/src/WireMock.Net/Serialization/WebhookMapper.cs
index ba72e9b1..5550190f 100644
--- a/src/WireMock.Net/Serialization/WebhookMapper.cs
+++ b/src/WireMock.Net/Serialization/WebhookMapper.cs
@@ -39,7 +39,7 @@ internal static class WebhookMapper
if (!Enum.TryParse(model.Request.TransformerReplaceNodeOptions, out var option))
{
- option = ReplaceNodeOptions.None;
+ option = ReplaceNodeOptions.Evaluate;
}
webhook.Request.TransformerReplaceNodeOptions = option;
}
diff --git a/src/WireMock.Net/Server/WireMockServer.ConvertMapping.cs b/src/WireMock.Net/Server/WireMockServer.ConvertMapping.cs
index 1368b06d..1e3bbcb5 100644
--- a/src/WireMock.Net/Server/WireMockServer.ConvertMapping.cs
+++ b/src/WireMock.Net/Server/WireMockServer.ConvertMapping.cs
@@ -250,7 +250,7 @@ public partial class WireMockServer
if (!Enum.TryParse(responseModel.TransformerReplaceNodeOptions, out var option))
{
- option = ReplaceNodeOptions.None;
+ option = ReplaceNodeOptions.Evaluate;
}
responseBuilder = responseBuilder.WithTransformer(
transformerType,
diff --git a/src/WireMock.Net/Settings/WireMockServerSettings.cs b/src/WireMock.Net/Settings/WireMockServerSettings.cs
index 7422046a..a03aa4a9 100644
--- a/src/WireMock.Net/Settings/WireMockServerSettings.cs
+++ b/src/WireMock.Net/Settings/WireMockServerSettings.cs
@@ -10,272 +10,279 @@ using WireMock.Logging;
using WireMock.Matchers;
using WireMock.RegularExpressions;
using WireMock.Types;
+using System.Globalization;
#if USE_ASPNETCORE
using Microsoft.Extensions.DependencyInjection;
#endif
-namespace WireMock.Settings
+namespace WireMock.Settings;
+
+///
+/// WireMockServerSettings
+///
+public class WireMockServerSettings
{
///
- /// WireMockServerSettings
+ /// Gets or sets the http port.
///
- public class WireMockServerSettings
- {
- ///
- /// Gets or sets the http port.
- ///
- [PublicAPI]
- public int? Port { get; set; }
+ [PublicAPI]
+ public int? Port { get; set; }
- ///
- /// Gets or sets the use SSL.
- ///
- // ReSharper disable once InconsistentNaming
- [PublicAPI]
- public bool? UseSSL { get; set; }
+ ///
+ /// Gets or sets the use SSL.
+ ///
+ // ReSharper disable once InconsistentNaming
+ [PublicAPI]
+ public bool? UseSSL { get; set; }
- ///
- /// Defines on which scheme (http/https) to host. (This overrides the UseSSL value).
- ///
- [PublicAPI]
- public HostingScheme? HostingScheme { get; set; }
+ ///
+ /// Defines on which scheme (http/https) to host. (This overrides the UseSSL value).
+ ///
+ [PublicAPI]
+ public HostingScheme? HostingScheme { get; set; }
- ///
- /// Gets or sets whether to start admin interface.
- ///
- [PublicAPI]
- public bool? StartAdminInterface { get; set; }
+ ///
+ /// Gets or sets whether to start admin interface.
+ ///
+ [PublicAPI]
+ public bool? StartAdminInterface { get; set; }
- ///
- /// Gets or sets if the static mappings should be read at startup.
- ///
- [PublicAPI]
- public bool? ReadStaticMappings { get; set; }
+ ///
+ /// Gets or sets if the static mappings should be read at startup.
+ ///
+ [PublicAPI]
+ public bool? ReadStaticMappings { get; set; }
- ///
- /// Watch the static mapping files + folder for changes when running.
- ///
- [PublicAPI]
- public bool? WatchStaticMappings { get; set; }
+ ///
+ /// Watch the static mapping files + folder for changes when running.
+ ///
+ [PublicAPI]
+ public bool? WatchStaticMappings { get; set; }
- ///
- /// A value indicating whether subdirectories within the static mappings path should be monitored.
- ///
- [PublicAPI]
- public bool? WatchStaticMappingsInSubdirectories { get; set; }
+ ///
+ /// A value indicating whether subdirectories within the static mappings path should be monitored.
+ ///
+ [PublicAPI]
+ public bool? WatchStaticMappingsInSubdirectories { get; set; }
- ///
- /// Gets or sets if the proxy and record settings.
- ///
- [PublicAPI]
- public ProxyAndRecordSettings? ProxyAndRecordSettings { get; set; }
+ ///
+ /// Gets or sets if the proxy and record settings.
+ ///
+ [PublicAPI]
+ public ProxyAndRecordSettings? ProxyAndRecordSettings { get; set; }
- ///
- /// Gets or sets the urls.
- ///
- [PublicAPI]
- public string[]? Urls { get; set; }
+ ///
+ /// Gets or sets the urls.
+ ///
+ [PublicAPI]
+ public string[]? Urls { get; set; }
- ///
- /// StartTimeout
- ///
- [PublicAPI]
- public int StartTimeout { get; set; } = 10000;
+ ///
+ /// StartTimeout
+ ///
+ [PublicAPI]
+ public int StartTimeout { get; set; } = 10000;
- ///
- /// Allow Partial Mapping (default set to false).
- ///
- [PublicAPI]
- public bool? AllowPartialMapping { get; set; }
+ ///
+ /// Allow Partial Mapping (default set to false).
+ ///
+ [PublicAPI]
+ public bool? AllowPartialMapping { get; set; }
- ///
- /// The username needed for __admin access.
- ///
- [PublicAPI]
- public string? AdminUsername { get; set; }
+ ///
+ /// The username needed for __admin access.
+ ///
+ [PublicAPI]
+ public string? AdminUsername { get; set; }
- ///
- /// The password needed for __admin access.
- ///
- [PublicAPI]
- public string? AdminPassword { get; set; }
+ ///
+ /// The password needed for __admin access.
+ ///
+ [PublicAPI]
+ public string? AdminPassword { get; set; }
- ///
- /// The AzureAD Tenant needed for __admin access.
- ///
- [PublicAPI]
- public string? AdminAzureADTenant { get; set; }
+ ///
+ /// The AzureAD Tenant needed for __admin access.
+ ///
+ [PublicAPI]
+ public string? AdminAzureADTenant { get; set; }
- ///
- /// The AzureAD Audience / Resource for __admin access.
- ///
- [PublicAPI]
- public string? AdminAzureADAudience { get; set; }
+ ///
+ /// The AzureAD Audience / Resource for __admin access.
+ ///
+ [PublicAPI]
+ public string? AdminAzureADAudience { get; set; }
- ///
- /// The RequestLog expiration in hours (optional).
- ///
- [PublicAPI]
- public int? RequestLogExpirationDuration { get; set; }
+ ///
+ /// The RequestLog expiration in hours (optional).
+ ///
+ [PublicAPI]
+ public int? RequestLogExpirationDuration { get; set; }
- ///
- /// The MaxRequestLog count (optional).
- ///
- [PublicAPI]
- public int? MaxRequestLogCount { get; set; }
+ ///
+ /// The MaxRequestLog count (optional).
+ ///
+ [PublicAPI]
+ public int? MaxRequestLogCount { get; set; }
- ///
- /// Action which is called (with the IAppBuilder or IApplicationBuilder) before the internal WireMockMiddleware is initialized. [Optional]
- ///
- [PublicAPI]
- [JsonIgnore]
- public Action