Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configure IgnoreCase in settings #695

Merged
merged 4 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,33 @@ public class WireMockOpenApiParserSettings
/// Are examples generated dynamically?
/// </summary>
public bool DynamicExamples { get; set; } = false;

/// <summary>
/// Is headers case sensitive? (default is true).
/// true = no case sensitive;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add these two lines:

        /// true = no case sensitive;
        /// false = case sensitive 

You can remove these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefH Done!

/// false = case sensitive
/// </summary>
public bool IgnoreCaseHeaders { get; set; } = true;

/// <summary>
/// Is query params case sensitive? (default is true).
/// true = no case sensitive;
/// false = case sensitive
/// </summary>
public bool IgnoreCaseQueryParams { get; set; } = true;

/// <summary>
/// Is request body case sensitive? (default is true).
/// true = no case sensitive;
/// false = case sensitive
/// </summary>
public bool IgnoreCaseRequestBody { get; set; } = true;

/// <summary>
/// Is example values case sensitive? (default is true).
/// true = no case sensitive;
/// false = case sensitive
/// </summary>
public bool IgnoreCaseExampleValues { get; set; } = true;
}
}