Skip to content

Clarify AddValidation behavior vs nullability/binding semantics#65497

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/compare-minimal-api-nullable-behavior
Draft

Clarify AddValidation behavior vs nullability/binding semantics#65497
Copilot wants to merge 1 commit intomainfrom
copilot/compare-minimal-api-nullable-behavior

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 21, 2026

Clarify AddValidation behavior vs nullability/binding semantics

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Clarify AddValidation vs NRT binding effects

Description

This update addresses whether AddValidation behavior changes when endpoint parameters or JSON body properties move from nullable-oblivious to non-nullable reference types.
Conclusion: validation semantics from AddValidation are largely unchanged; behavior differences come from Minimal API binding optionality/requiredness decisions upstream.

  • Scope

    • Clarifies the separation between:
      • Minimal API binding nullability behavior (RequestDelegateFactory)
      • Validation execution (ValidationEndpointFilterFactory + Validatable*Info)
    • No product code changes; this is an implementation-backed behavior clarification.
  • Key behavior findings

    • AddValidation registers validation resolvers/filtering and does not introduce independent NRT-required semantics for reference types.
    • Runtime validation nullability checks are not NRT-sensitive for reference types.
    • Binding can change request outcomes (e.g., required parameter failures) when nullability annotations change, before validation filter execution.
  • Relevant implementation points

    • ValidationServiceCollectionExtensions.AddValidation(...)
    • ValidationEndpointFilterFactory skips null arguments and validates bound values.
    • RequestDelegateFactory.IsOptionalParameter(...) uses nullability metadata to determine required/optional binding behavior.
// Binding semantics can differ with NRT:
app.MapGet("/{value}", (string value) => value);      // required binding
app.MapGet("/{value}", (string? value) => value ?? ""); // optional binding

// Validation semantics remain attribute/type driven:
builder.Services.AddValidation();
app.MapPost("/", ([Required] string name) => Results.Ok(name));

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Investigate minimal API behavior with nullable reference types Document minimal API nullability coverage across RDF/RDG tests Feb 21, 2026
Copilot AI requested a review from halter73 February 21, 2026 02:34
Copilot AI changed the title Document minimal API nullability coverage across RDF/RDG tests Clarify AddValidation behavior vs nullability/binding semantics Feb 21, 2026
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Feb 21, 2026
@gfoidl gfoidl added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants