dotnet/aspnetcore

minimal api-- FromQuery problem for complex object

infofromca opened this issue · 7 comments

Background and Motivation

when i use web api (mvc)

public class ShoppingCartController : Controller
{    
    [HttpGet]
    [Route("estimate/{sku}/{shoppingCartId?}")]
    public async Task<ActionResult<ShoppingCartLineViewModelVM>> EstimateProductAsync(
            string sku,
            string? shoppingCartId,
            [FromQuery] Address? shipping,
            [FromQuery] Address? billing
        )
        )

everything is working as expected.

but when i use minimal api, got exception

  public static IEndpointRouteBuilder AddEstimateProductAsyncEndpoint(this ```
IEndpointRouteBuilder builder)
    {
        builder.MapGet("api/ShoppingCart/EstimateProduct/{sku}/{shoppingCartId}", EstimateProductAsync)
            .AllowAnonymous()
            .DisableAntiforgery();
        return builder;
    }   
    private static async Task<IResult> EstimateProductAsync(
        string sku,
        string? shoppingCartId,
        [FromQuery] Address? shipping,
        [FromQuery] Address? billing     
        )
which indicated both  [FromQuery] Address? shipping,
    [FromQuery] Address? billing   are UNKNOWN AND SHOULD HAVE TryParce method

Proposed API

minimal api should be better than mvc api , at least the same