Skip to content

Conversation

@captainsafia
Copy link
Member

Addresses #61379.

@ghost ghost added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 8, 2025
@captainsafia captainsafia 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 area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Apr 8, 2025
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Apr 16, 2025
@captainsafia
Copy link
Member Author

/azp run

@dotnet-policy-service dotnet-policy-service bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Apr 16, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@captainsafia
Copy link
Member Author

Bump @BrennanConroy and @DeagleGross for a review if you have the chance.

public override bool IsValid(object? value) => value is int number && number % 2 == 0;
}
public record SubType([Required] string RequiredProperty = "some-value", [StringLength(10)] string? StringWithLength = default);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should test with a record like:

public record Person
{
    public required string FirstName { get; init; }
    public required string LastName { get; init; }
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we don't have any tests for non-records with primary ctors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I need to add tests for both those scenarios.

Copy link
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one comment on the attribute syntax. Rest looked good to a PM's eyes.

}
public record ValidatableRecord(
[Range(10, 100)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought validation attributes had to have property: on them to be effective -- is that not true?

I have confirmed that the attribute on the parameter does not result in the range being reflected in the generated OpenApi document -- so at the very least there is some inconsistency here I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought validation attributes had to have property: on them to be effective -- is that not true?

That's only a constraint that exists in the MVC universe. Since we have the opportunity to deliver a better experience here I figured we'd do that.

I have confirmed that the attribute on the parameter does not result in the range being reflected in the generated OpenApi document -- so at the very least there is some inconsistency here I think.

Yep, that's a separate bug we should file -- especially now that minimal APIs support both. Although we'll want to be mindful of only respecting it for minimal APIs. Hmmm.... 🤔

@captainsafia captainsafia merged commit c22a853 into main Apr 17, 2025
27 checks passed
@captainsafia captainsafia deleted the safia/fix-valid-gen branch April 17, 2025 17:36
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview4 milestone Apr 17, 2025
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