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
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
keahpeters committed Apr 28, 2024
commit e021c47ff61e1eac5de1f8eecd165f068e2ef423
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void ActionWithIntParameterWithRequiredAttribute([Required]int param)
public void ActionWithIntParameterWithSwaggerIgnoreAttribute([SwaggerIgnore] int param)
{ }

public void ActionWithAcceptFromHeaderParameter([FromHeader(Name = "Accept")] int accept)
public void ActionWithAcceptFromHeaderParameter([FromHeader] string accept)
{ }

public void ActionWithObjectParameter(XmlAnnotatedType param)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Swashbuckle.AspNetCore.TestSupport;
using Xunit;
using System.Threading.Tasks;
using System.Reflection.Metadata;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
Expand Down Expand Up @@ -536,6 +537,7 @@ public void GetSwagger_IgnoresParameters_IfActionParameterIsIllegalHeaderParamet
[Fact]
public void GetSwagger_GenerateParametersSchemas_IfActionParameterIsIllegalHeaderParameterWithProvidedOpenApiOperation()
{
var parameter = typeof(FakeController).GetMethod(nameof(FakeController.ActionWithAcceptFromHeaderParameter)).GetParameters()[0];
var methodInfo = typeof(FakeController).GetMethod(nameof(FakeController.ActionWithAcceptFromHeaderParameter));
var actionDescriptor = new ActionDescriptor
{
Expand All @@ -548,7 +550,7 @@ public void GetSwagger_GenerateParametersSchemas_IfActionParameterIsIllegalHeade
{
new OpenApiParameter
{
Name = "accept"
Name = parameter.Name
}
}
}
Expand All @@ -571,9 +573,9 @@ public void GetSwagger_GenerateParametersSchemas_IfActionParameterIsIllegalHeade
{
new ApiParameterDescription
{
Name = "accept",
Name = parameter.Name,
Source = BindingSource.Header,
ModelMetadata = ModelMetadataFactory.CreateForType(typeof(string))
ModelMetadata = ModelMetadataFactory.CreateForParameter(parameter)
}
}),
}
Expand Down