You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe the problem.
I'm using ApiExplorer to get info about the endpoints in my application. For parameters (e.g. route/query) and the request body I can take the ApiParameterDescription and try to cast it to IPropertyInfoParameterDescriptor or IParameterInfoParameterDescriptor to get the corresponding PropertyInfo or ParameterInfo. With these, I can use NullabilityInfoContext to get the NullabilityInfo for the API parameter. This provides nullability info about reference types when using nullable reference types.
However, for the response types in ApiDescription.SupportedResponseTypes I haven't been able to get this information. I need this information to know if the API returns stuff that can be null or not. If an endpoint returns e.g. Dictionary<int, string?>, I want to know that the dictionary values can be null.
I could try looking into the ActionDescriptor to find the MethodInfo and get the return parameter info from there, but I'm not sure if that works for e.g. Minimal API and it definitely won't work if the endpoint has defined response types using ProducesResponseTypeAttribute.
Describe the solution you'd like
To get nullability info, you need to pass one of the following to a NullabilityInfoContext:
EventInfo
FieldInfo
ParameterInfo
PropertyInfo
ApiResponseType (the type of the elements inside ApiDescription.SupportedResponseTypes) needs to contain one of these. Could also be one or multiple subtypes of ApiResponseType containing it, in the same way subtypes of ApiParameterDescription can be cast to IPropertyInfoParameterDescriptor or IParameterInfoParameterDescriptor and contain a PropertyInfo or ParameterInfo.
Obviously to get the info, you also need to be able to provide the info. When only using the return type of the action method, this is trivial (as mentioned before, get the return ParameterInfo from the MethodInfo).
But when using ProducesResponseTypeAttribute it's not. Right now the response type is passed to the attribute as a type parameter and that doesn't allow passing nullable information. The attributes ProducesAttribute, ProducesDefaultResponseType and ProducesErrorResponseType probably also need to support this.
Additional context
No response
The text was updated successfully, but these errors were encountered:
ghost
added
the
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
label
Aug 9, 2023
Small addition: instead of a FieldInfo/ParameterInfo/PropertyInfo, the ApiResponseType could also contain a NullabilityInfo directly. In this case it'd make sense to also have the ApiParameterDescription contain a NullabilityInfo.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I'm using ApiExplorer to get info about the endpoints in my application. For parameters (e.g. route/query) and the request body I can take the
ApiParameterDescription
and try to cast it toIPropertyInfoParameterDescriptor
orIParameterInfoParameterDescriptor
to get the correspondingPropertyInfo
orParameterInfo
. With these, I can useNullabilityInfoContext
to get theNullabilityInfo
for the API parameter. This provides nullability info about reference types when using nullable reference types.However, for the response types in
ApiDescription.SupportedResponseTypes
I haven't been able to get this information. I need this information to know if the API returns stuff that can be null or not. If an endpoint returns e.g.Dictionary<int, string?>
, I want to know that the dictionary values can be null.I could try looking into the
ActionDescriptor
to find theMethodInfo
and get the return parameter info from there, but I'm not sure if that works for e.g. Minimal API and it definitely won't work if the endpoint has defined response types usingProducesResponseTypeAttribute
.Describe the solution you'd like
To get nullability info, you need to pass one of the following to a
NullabilityInfoContext
:EventInfo
FieldInfo
ParameterInfo
PropertyInfo
ApiResponseType
(the type of the elements insideApiDescription.SupportedResponseTypes
) needs to contain one of these. Could also be one or multiple subtypes ofApiResponseType
containing it, in the same way subtypes ofApiParameterDescription
can be cast toIPropertyInfoParameterDescriptor
orIParameterInfoParameterDescriptor
and contain aPropertyInfo
orParameterInfo
.Obviously to get the info, you also need to be able to provide the info. When only using the return type of the action method, this is trivial (as mentioned before, get the return
ParameterInfo
from theMethodInfo
).But when using
ProducesResponseTypeAttribute
it's not. Right now the response type is passed to the attribute as a type parameter and that doesn't allow passing nullable information. The attributesProducesAttribute
,ProducesDefaultResponseType
andProducesErrorResponseType
probably also need to support this.Additional context
No response
The text was updated successfully, but these errors were encountered: