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

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

Closed
JanuszRybinski opened this issue Nov 22, 2021 · 2 comments
Labels

Comments

@JanuszRybinski
Copy link

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

@leolplex
Copy link
Contributor

Hello @JanuszRybinski / @StefH ,

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

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

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

@StefH
Copy link
Collaborator

StefH commented Nov 23, 2021

You can create a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants