Skip to content

Honor default value provided in parameters for route handlers #47266

Closed
@amcasey

Description

@amcasey

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

There are a number of ways to make it unnecessary to pass an argument corresponding to a given parameter. We should think about what we want to do in these scenarios with RDG.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/{purple:int}", HandleRequest);

app.Run();

static string HandleRequest(int purple, int orange = 1) => "Hello World!";
static string HandleRequest(int purple, [System.Runtime.InteropServices.OptionalAttribute] int orange) => "Hello World!";
static string HandleRequest(int purple, params int[] orange) => "Hello World!";

Describe the solution you'd like

I see that parameters can't already be flagged as optional:

// Endpoint Parameter: purple (Type = int, IsOptional = False, IsParsable = True, Source = RouteOrQuery)

Maybe we just need to recognize more forms of optionality?

Additional context

No response

Metadata

Metadata

Assignees

Labels

area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.feature-rdg

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions