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

Filter illegal header fields #2842

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
martincostello marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public static class ApiParameterDescriptionExtensions
private static readonly HashSet<string> IllegalHeaderParameters = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
HeaderNames.Accept,
HeaderNames.ContentType,
HeaderNames.Authorization
HeaderNames.Authorization,
HeaderNames.ContentType
};

public static bool IsRequiredParameter(this ApiParameterDescription apiParameter)
Expand Down Expand Up @@ -122,7 +122,7 @@ internal static bool IsFromForm(this ApiParameterDescription apiParameter)

internal static bool IsIllegalHeaderParameter(this ApiParameterDescription apiParameter)
{
// Certian header parameters are not allowed and should be described using the corresponding OpenAPI keywords
// Certain header parameters are not allowed and should be described using the corresponding OpenAPI keywords
// https://swagger.io/docs/specification/describing-parameters/#header-parameters
return apiParameter.Source == BindingSource.Header && IllegalHeaderParameters.Contains(apiParameter.Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ public void GetSwagger_IgnoresParameters_IfActionParameterIsIllegalHeaderParamet
Name = fromHeaderAttribute?.Name ?? illegalParameter.Name,
Source = BindingSource.Header,
ModelMetadata = ModelMetadataFactory.CreateForParameter(illegalParameter)
},
new ApiParameterDescription
{
Name = "param",
Source = BindingSource.Header
}
}
)
Expand Down Expand Up @@ -563,6 +568,10 @@ public void GetSwagger_GenerateParametersSchemas_IfActionParameterIsIllegalHeade
new OpenApiParameter
{
Name = illegalParameterName,
},
new OpenApiParameter
{
Name = "param",
}
}
}
Expand All @@ -588,10 +597,16 @@ public void GetSwagger_GenerateParametersSchemas_IfActionParameterIsIllegalHeade
Name = illegalParameterName,
Source = BindingSource.Header,
ModelMetadata = ModelMetadataFactory.CreateForParameter(illegalParameter)
},
new ApiParameterDescription
{
Name = "param",
Source = BindingSource.Header,
ModelMetadata = ModelMetadataFactory.CreateForType(typeof(string))
}
}),
}
);
); ;
keahpeters marked this conversation as resolved.
Show resolved Hide resolved

var document = subject.GetSwagger("v1");

Expand Down