Skip to content

Minimal API validation should support validation attributes on primary constructor parameters #61526

Open
@captainsafia

Description

@captainsafia

The implementation currently doesn't support scenarios like the following:

public class SubType(string? requiredProperty, [StringLength(10)] string? stringWithLength)
{
    [Required]
    public string RequiredProperty { get; } = requiredProperty;

    public string? StringWithLength { get; } = stringWithLength;
}

Where attributes are applied on parameters for a primary constructor for a class. We need to update the constructor discovery logic to be less greedy when discovering primary constructors for non-record types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions