-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support setting ApiParameterRouetInfo for endpoints #37470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs
Outdated
Show resolved
Hide resolved
src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs
Outdated
Show resolved
Hide resolved
|
||
return new ApiParameterRouteInfo() | ||
{ | ||
Constraints = constraints.AsEnumerable(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we worried about people casting and mutating this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible for someone to mutate this in a harmful way (say removing the constraints that we discovered). I don't anticipate this being common but it does't hurt to lock this down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsEnumerable
doesn't do much though - https://source.dot.net/#System.Linq/System/Linq/Enumerable.cs,10. You would need to use AsReadOnly
or ReadOnlyCollection
if you truly want to lock this down.
But I'm of the shoot you own foot, now you have to go figure out how to bandage it school of thought. If somebody messes with the constraints and things don't work well, they're kinda at fault, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to use AsReadOnly or ReadOnlyCollection if you truly want to lock this down.
Yep, to clarify by "it doesn't hurt to lock this down" I meant use AsReadOnly
here as in 43fd3cd.
But I'm of the shoot you own foot, now you have to go figure out how to bandage it school of thought. If somebody messes with the constraints and things don't work well, they're kinda at fault, no?
Agreed, but it doesn't hurt to be explicit about the fact that we don't recommend doing things like this by making it read-only.
Contributes towards #36525.
The ApiExplorer for MVC populates each route parameter with an
ApiParameterRouteInfo
object that contains information about the constraints defined on a route parameter. This metadata can be used by OpenAPI libraries to generate more complete schemas for route parameters. This PR updates the ApiDescriptorProvider for endpoints to generate the same metadata.Note: both Swashbuckle and NSwag don't currently respect the values in the
RouteInfo
property so there is some additional work to read from this info.