Move the abstract Validatable*Info from Microsoft.Extensions.Validation to be source-generated#67956
Conversation
oroztocil
left a comment
There was a problem hiding this comment.
Only few minor comments. When the tests are fixed this should be solid. Run a few samples manually before merging, please (or let me know if you want help there).
|
@copilot Tests |
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Updated both snapshot files. The issue was that a recent commit removed |
Validatable*Info from Microsoft.Extensions.Validation to be source-generated
|
@copilot There are additional test failures in Investigate that. |
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
…e resolver in AddValidation Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
... Fixed in the latest commit. The root cause was that The fix creates an internal |
…g runtime resolver in AddValidation" This reverts commit 1a52a50. Users are expected to have the source generator available; restoring the source generator reference to the test project instead. Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Done. Reverted in commit 57e1ff3. The |
Address API feedback on #67960: ValidationError carried a plural Errors list that the generator always populated with a single message, while AddValidationError already groups errors by Path. Collapse the redundant axis to a scalar string ErrorMessage and rely on the per-path list. Also make ValidationError a sealed class instead of a readonly struct so default(ValidationError) no longer bypasses the required members and hands back null Name/Path/ErrorMessage. It is only materialized on validation failure, so the extra allocation is not a concern. Update the generator templates, the Blazor EditContext integration, the minimal API endpoint filter, and all affected tests and snapshots. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf
…n from generated resolvers Address PR review feedback and fix the Http.Extensions.Tests CI build break. - ValidationContext for type-level validation now uses `value ?? _throwawayObjectInstance` instead of always passing the throwaway placeholder, so IValidatableObject.Validate (sync and async) receives the model being validated as ObjectInstance. Previously user code that cast ObjectInstance back to the model threw. Adds a regression test covering both paths. - The generated file-local resolver/type-info implementations no longer emit [NotNullWhen] on their out parameters. The public interfaces (IValidatableInfoResolver, IValidatableTypeInfo) keep the attribute, so callers are unaffected, but the emitted code no longer references System.Diagnostics.CodeAnalysis.NotNullWhenAttribute. That reference was ambiguous (CS0433) in compilations where another source generator (e.g. the RequestDelegateGenerator) contributes an internal polyfill of the same attribute via InternalsVisibleTo, which broke the build of Microsoft.AspNetCore.Http.Extensions.Tests. CS8767 on the implementations is suppressed in the generated file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf
|
Possibly flaky test: FYI @ilonatommy |
|
/backport to release/11.0-preview7 |
|
Started backporting to |
|
@Youssef1313 an error occurred while backporting to |
…tion to be source-generated (#67956) * Refactor validation * Step 2 * Refactor * Move to SG * Introduce * Rename * Snapshots, rename * Generated * Namespace * Reduce comments * Avoid usings. Use global:: * Stable * Remove unused usings * Update failing snapshot tests to remove BOM and pragma Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> * Initial plan: fix ValidationEndpointFilterFactory test failures Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> * Fix ValidationEndpointFilterFactory test failures by restoring runtime resolver in AddValidation Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> * Revert "Fix ValidationEndpointFilterFactory test failures by restoring runtime resolver in AddValidation" This reverts commit 1a52a50. Users are expected to have the source generator available; restoring the source generator reference to the test project instead. Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com> * Simplify ValidationError to a single ErrorMessage and make it a class Address API feedback on #67960: ValidationError carried a plural Errors list that the generator always populated with a single message, while AddValidationError already groups errors by Path. Collapse the redundant axis to a scalar string ErrorMessage and rely on the per-path list. Also make ValidationError a sealed class instead of a readonly struct so default(ValidationError) no longer bypasses the required members and hands back null Name/Path/ErrorMessage. It is only materialized on validation failure, so the extra allocation is not a concern. Update the generator templates, the Blazor EditContext integration, the minimal API endpoint filter, and all affected tests and snapshots. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf * Pass the validated instance to IValidatableObject and drop NotNullWhen from generated resolvers Address PR review feedback and fix the Http.Extensions.Tests CI build break. - ValidationContext for type-level validation now uses `value ?? _throwawayObjectInstance` instead of always passing the throwaway placeholder, so IValidatableObject.Validate (sync and async) receives the model being validated as ObjectInstance. Previously user code that cast ObjectInstance back to the model threw. Adds a regression test covering both paths. - The generated file-local resolver/type-info implementations no longer emit [NotNullWhen] on their out parameters. The public interfaces (IValidatableInfoResolver, IValidatableTypeInfo) keep the attribute, so callers are unaffected, but the emitted code no longer references System.Diagnostics.CodeAnalysis.NotNullWhenAttribute. That reference was ambiguous (CS0433) in compilations where another source generator (e.g. the RequestDelegateGenerator) contributes an internal polyfill of the same attribute via InternalsVisibleTo, which broke the build of Microsoft.AspNetCore.Http.Extensions.Tests. CS8767 on the implementations is suppressed in the generated file. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Ondrej Roztocil <roztocil@outlook.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf
Fixes #67960
See the linked issue for all the details on why we are making these changes. Copying some highlights:
Validatable[Type|Property|Parameter]Infoin the public API. So we are moving them to be source-generated as file classes in user assemblies.ValidationError. This includes all the info that Blazor needs and is how we are able to delete the OnValidationError event.