-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed as not planned
Closed as not planned
Copy link
Labels
✔️ Resolution: By DesignResolved because the behavior in this issue is the intended design.Resolved because the behavior in this issue is the intended design.Status: Resolvedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIsIssues related to model validation in minimal and controller-based APIs
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Adding Minimal API validation to an existing application running .NET 10, `` types are generated for TimeProvider
despite being a service.
This was addressed previously in #61392, so I assume this is an edge case missed previously.
My guess would be because the endpoint points to a method group, rather than being defined inline:
group.MapGet("/time", GetTime);
private static Ok<TimeResponse> GetTime(TimeProvider timeProvider) { ... }
Viewing the source generator output shows the following code in the TryGetValidatableTypeInfo()
method:
if (type == typeof(global::System.TimeZoneInfo))
{
validatableInfo = new GeneratedValidatableTypeInfo(
type: typeof(global::System.TimeZoneInfo),
members: [
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::System.TimeZoneInfo),
propertyType: typeof(global::System.TimeZoneInfo),
name: "Local",
displayName: "Local"
),
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::System.TimeZoneInfo),
propertyType: typeof(global::System.TimeZoneInfo),
name: "Utc",
displayName: "Utc"
),
]
);
return true;
}
if (type == typeof(global::System.TimeProvider))
{
validatableInfo = new GeneratedValidatableTypeInfo(
type: typeof(global::System.TimeProvider),
members: [
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::System.TimeProvider),
propertyType: typeof(global::System.TimeZoneInfo),
name: "LocalTimeZone",
displayName: "LocalTimeZone"
),
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::System.TimeProvider),
propertyType: typeof(global::System.TimeProvider),
name: "System",
displayName: "System"
),
]
);
return true;
}
Adding [FromServices]
to the endpoint code explicitly removes the types from the generated code.
- private static Ok<TimeResponse> GetTime(TimeProvider timeProvider)
+ private static Ok<TimeResponse> GetTime([FromServices] TimeProvider timeProvider)
Expected Behavior
No GeneratedValidatableTypeInfo
is generated for TimeProvider
.
Steps To Reproduce
- Clone martincostello/api@024a90b
- Run
build.ps1
in the root of the repo - Run
startvs.cmd
- View the generated code for
Microsoft.Extensions.Validation.ValidationsGenerator
in Visual Studio.
Exceptions (if any)
None.
.NET Version
10.0.100-rc.1.25414.111
Anything else?
No response
Metadata
Metadata
Assignees
Labels
✔️ Resolution: By DesignResolved because the behavior in this issue is the intended design.Resolved because the behavior in this issue is the intended design.Status: Resolvedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIsIssues related to model validation in minimal and controller-based APIs