Case insensitive and ignoring optional path and header parameters in OpenApiPathsMapper #387

Closed
opened 2025-12-29 15:22:27 +01:00 by adam · 2 comments
Owner

Originally created by @JanuszRybinski on GitHub (Nov 22, 2021).

Hello @StefH and @leolplex,

related to (#691) but I decided to start a new discussion. While I testing OpenApi Parser, I encountered an interesting behavior of HttpRequestMessage, I will show on an example.

Assuming I have this definition of request:

  "paths": {
    "/somethinks": {
      "put": {
        "parameters": [
          {
            "name": "X-Correlation-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
       ]
     }
  }

And I want to define a request for this:

using (var request = new System.Net.Http.HttpRequestMessage())
{
    request.Headers.TryAddWithoutValidation("X-Correlation-Id", "some value");
}

I did not check why exactly, but a header called "X-Correlation-ID" will be added to the request. By this small difference there is no matching mapping. In my opinion, headers should not be case-sensitive. To be sure, I checked what is in the RFC (https://www.rfc-editor.org/rfc/rfc7230#section-3.2). I have another idea to set case ignore in MapRequestHeaders:

var list = headers
    .Select(qp => new HeaderModel
    {
        Name = qp.Name,
        Matchers = new[]
        {
            GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
        },
        IgnoreCase = true
    })
    .ToList();

It seems to me that a similar setting also could be used in MapQueryParameters.

Additionally, I think that only the required parameters and headers should be taken into mappings:

var list = queryParameters
    .Where(qp => qp.Required)
var list = headers
    .Where(h => h.Required)

What is your opinion? If you agree, should I submit a new PR, or it can be added as part of #691?

Regards,
Janusz

Originally created by @JanuszRybinski on GitHub (Nov 22, 2021). Hello @StefH and @leolplex, related to (#691) but I decided to start a new discussion. While I testing OpenApi Parser, I encountered an interesting behavior of HttpRequestMessage, I will show on an example. Assuming I have this definition of request: ```json "paths": { "/somethinks": { "put": { "parameters": [ { "name": "X-Correlation-Id", "in": "header", "required": true, "schema": { "type": "string" } } ] } } ``` And I want to define a request for this: ```c# using (var request = new System.Net.Http.HttpRequestMessage()) { request.Headers.TryAddWithoutValidation("X-Correlation-Id", "some value"); } ``` I did not check why exactly, but a header called "X-Correlation-ID" will be added to the request. By this small difference there is no matching mapping. In my opinion, headers should not be case-sensitive. To be sure, I checked what is in the RFC (https://www.rfc-editor.org/rfc/rfc7230#section-3.2). I have another idea to set case ignore in [MapRequestHeaders](https://github.com/WireMock-Net/WireMock.Net/blob/d9123ee3bdc800cfb0eb3fea19a58821abc8db23/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs#L339): ```c# var list = headers .Select(qp => new HeaderModel { Name = qp.Name, Matchers = new[] { GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse) }, IgnoreCase = true }) .ToList(); ``` It seems to me that a similar setting also could be used in [MapQueryParameters](https://github.com/WireMock-Net/WireMock.Net/blob/d9123ee3bdc800cfb0eb3fea19a58821abc8db23/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs#L323). Additionally, I think that only the required parameters and headers should be taken into mappings: ```c# var list = queryParameters .Where(qp => qp.Required) ``` ```c# var list = headers .Where(h => h.Required) ``` What is your opinion? If you agree, should I submit a new PR, or it can be added as part of #691? Regards, Janusz
adam added the feature label 2025-12-29 15:22:27 +01:00
adam closed this issue 2025-12-29 15:22:28 +01:00
Author
Owner

@leolplex commented on GitHub (Nov 23, 2021):

Hello @JanuszRybinski / @StefH ,

It all makes sense to me, I also would add the required parameters in request body.

8865543bf1/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs (L64)

if (operation.RequestBody != null && operation.RequestBody.Content != null && operation.RequestBody.Required)

@leolplex commented on GitHub (Nov 23, 2021): Hello @JanuszRybinski / @StefH , It all makes sense to me, I also would add the required parameters in request body. https://github.com/WireMock-Net/WireMock.Net/blob/8865543bf117bbf7cfcd90bb43714715ed0238ee/src/WireMock.Net.OpenApiParser/Mappers/OpenApiPathsMapper.cs#L64 ` if (operation.RequestBody != null && operation.RequestBody.Content != null && operation.RequestBody.Required)`
Author
Owner

@StefH commented on GitHub (Nov 23, 2021):

You can create a new PR.

@StefH commented on GitHub (Nov 23, 2021): You can create a new PR.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#387