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

[release/9.0] Don't throw exception for parameters with custom binding source #59533

Open
wants to merge 2 commits into
base: release/9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/OpenApi/src/Services/OpenApiDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private async Task<OpenApiResponse> GetResponseAsync(
"Query" => ParameterLocation.Query,
"Header" => ParameterLocation.Header,
"Path" => ParameterLocation.Path,
_ => throw new InvalidOperationException($"Unsupported parameter source: {parameter.Source.Id}")
_ => ParameterLocation.Query
},
Required = IsRequired(parameter),
Schema = await _componentService.GetOrCreateSchemaAsync(GetTargetType(description, parameter), scopedServiceProvider, schemaTransformers, parameter, cancellationToken: cancellationToken),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.OpenApi.Models;

public partial class OpenApiDocumentServiceTests : OpenApiDocumentServiceTestBase
Expand Down Expand Up @@ -190,4 +191,29 @@ await VerifyOpenApiDocument(builder, document =>
Assert.Null(document.Paths["/api/content-type-lower"].Operations[OperationType.Get].Parameters);
});
}

[Fact]
public async Task GetOpenApiParameters_ToleratesCustomBindingSource()
{
var action = CreateActionDescriptor(nameof(ActionWithCustomBinder));

await VerifyOpenApiDocument(action, document =>
{
var operation = document.Paths["/custom-binding"].Operations[OperationType.Get];
var parameter = Assert.Single(operation.Parameters);
Assert.Equal("model", parameter.Name);
Assert.Equal(ParameterLocation.Query, parameter.In);
});
}

[Route("/custom-binding")]
private void ActionWithCustomBinder([ModelBinder(BinderType = typeof(CustomBinder))] Todo model) { }

public class CustomBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
return Task.CompletedTask;
}
}
}
Loading