Allow configure IgnoreCase in settings (#695)

* Add IgnoreCase = true in Request body, query parameters, headers, example value

* Ignorecase is configurable in settings!

* Remove unnecesary comments!
This commit is contained in:
Daniel L. Romero
2021-11-29 02:25:15 -05:00
committed by GitHub
parent 13c002fede
commit 4d80eb53fe
2 changed files with 25 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -115,6 +115,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
requestBodyModel.Matcher = new MatcherModel(); requestBodyModel.Matcher = new MatcherModel();
requestBodyModel.Matcher.Name = "JsonMatcher"; requestBodyModel.Matcher.Name = "JsonMatcher";
requestBodyModel.Matcher.Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented); requestBodyModel.Matcher.Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented);
requestBodyModel.Matcher.IgnoreCase = _settings.IgnoreCaseRequestBody;
return requestBodyModel; return requestBodyModel;
} }
@@ -327,6 +328,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
.Select(qp => new ParamModel .Select(qp => new ParamModel
{ {
Name = qp.Name, Name = qp.Name,
IgnoreCase = _settings.IgnoreCaseQueryParams,
Matchers = new[] Matchers = new[]
{ {
GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse) GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse)
@@ -344,6 +346,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
.Select(qp => new HeaderModel .Select(qp => new HeaderModel
{ {
Name = qp.Name, Name = qp.Name,
IgnoreCase = _settings.IgnoreCaseHeaders,
Matchers = new[] Matchers = new[]
{ {
GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse) GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
@@ -358,7 +361,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
{ {
return type switch return type switch
{ {
ExampleValueType.Value => new MatcherModel { Name = "ExactMatcher", Pattern = GetExampleValueAsStringForSchemaType(schema) }, ExampleValueType.Value => new MatcherModel { Name = "ExactMatcher", Pattern = GetExampleValueAsStringForSchemaType(schema), IgnoreCase = _settings.IgnoreCaseExampleValues },
_ => new MatcherModel { Name = "WildcardMatcher", Pattern = "*" } _ => new MatcherModel { Name = "WildcardMatcher", Pattern = "*" }
}; };

View File

@@ -36,5 +36,25 @@ namespace WireMock.Net.OpenApiParser.Settings
/// Are examples generated dynamically? /// Are examples generated dynamically?
/// </summary> /// </summary>
public bool DynamicExamples { get; set; } = false; public bool DynamicExamples { get; set; } = false;
/// <summary>
/// Is headers case sensitive? (default is true).
/// </summary>
public bool IgnoreCaseHeaders { get; set; } = true;
/// <summary>
/// Is query params case sensitive? (default is true).
/// </summary>
public bool IgnoreCaseQueryParams { get; set; } = true;
/// <summary>
/// Is request body case sensitive? (default is true).
/// </summary>
public bool IgnoreCaseRequestBody { get; set; } = true;
/// <summary>
/// Are example values case sensitive? (default is true).
/// </summary>
public bool IgnoreCaseExampleValues { get; set; } = true;
} }
} }