Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion src/OpenApi/src/Services/OpenApiDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private async Task<OpenApiResponse> GetResponseAsync(
"Query" => ParameterLocation.Query,
"Header" => ParameterLocation.Header,
"Path" => ParameterLocation.Path,
_ => throw new InvalidOperationException($"Unsupported parameter source: {parameter.Source.Id}")
_ => null
},
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.Null(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