Skip to content

Min API validation doesn't consider List<T>? members #61737

Closed
@sbomer

Description

@sbomer

The generator seems to skip List? members where T is a type with validation requirements. For example:

[ValidatableType]
class Model {
    public required List<DataType>? Data { get; init; }
    public required List<DataType2> Data2 { get; init; }
}

class DataType {
    [Required]
    public int Name { get; init; }
}

class DataType2 {
    [Required]
    public int Name { get; init; }
}

The generated type info for Model only contains the Data2 member:

        private ValidatableTypeInfo CreateModel()
        {
            return new GeneratedValidatableTypeInfo(
                type: typeof(global::Model),
                members: [
                    new GeneratedValidatablePropertyInfo(
                        containingType: typeof(global::Model),
                        propertyType: typeof(global::System.Collections.Generic.List<global::DataType2>),
                        name: "Data2",
                        displayName: "Data2"
                    ),
                ]
            );
        }

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