Skip to content

Commit

Permalink
Allow configure IgnoreCase in settings (#695)
Browse files Browse the repository at this point in the history
* Add IgnoreCase = true in Request body, query parameters, headers, example value

* Ignorecase is configurable in settings!

* Remove unnecesary comments!
  • Loading branch information
leolplex committed Nov 29, 2021
1 parent 13c002f commit 4d80eb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -115,6 +115,7 @@ private BodyModel MapRequestBody(object requestBody)
requestBodyModel.Matcher = new MatcherModel();
requestBodyModel.Matcher.Name = "JsonMatcher";
requestBodyModel.Matcher.Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented);
requestBodyModel.Matcher.IgnoreCase = _settings.IgnoreCaseRequestBody;
return requestBodyModel;
}

Expand Down Expand Up @@ -327,6 +328,7 @@ private IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> query
.Select(qp => new ParamModel
{
Name = qp.Name,
IgnoreCase = _settings.IgnoreCaseQueryParams,
Matchers = new[]
{
GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse)
Expand All @@ -344,6 +346,7 @@ private IList<HeaderModel> MapRequestHeaders(IEnumerable<OpenApiParameter> heade
.Select(qp => new HeaderModel
{
Name = qp.Name,
IgnoreCase = _settings.IgnoreCaseHeaders,
Matchers = new[]
{
GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
Expand All @@ -358,7 +361,7 @@ private MatcherModel GetExampleMatcherModel(OpenApiSchema schema, ExampleValueTy
{
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 = "*" }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,25 @@ public class WireMockOpenApiParserSettings
/// Are examples generated dynamically?
/// </summary>
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;
}
}

0 comments on commit 4d80eb5

Please sign in to comment.