-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[OpenAPI] Get parameter description with [FromQuery] #62986
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -494,11 +494,22 @@ private static bool IsRequired(ApiParameterDescription parameter) | |
} | ||
|
||
// Apply [Description] attributes on the parameter to the top-level OpenApiParameter object and not the schema. | ||
private static string? GetParameterDescriptionFromAttribute(ApiParameterDescription parameter) => | ||
parameter.ParameterDescriptor is IParameterInfoParameterDescriptor { ParameterInfo: { } parameterInfo } && | ||
parameterInfo.GetCustomAttributes().OfType<DescriptionAttribute>().LastOrDefault() is { } descriptionAttribute ? | ||
descriptionAttribute.Description : | ||
null; | ||
private static string? GetParameterDescriptionFromAttribute(ApiParameterDescription parameter) | ||
{ | ||
if (parameter.ParameterDescriptor is IParameterInfoParameterDescriptor { ParameterInfo: { } parameterInfo } && | ||
parameterInfo.GetCustomAttributes<DescriptionAttribute>().LastOrDefault() is { } parameterDescription) | ||
{ | ||
return parameterDescription.Description; | ||
} | ||
|
||
if (parameter.ModelMetadata is Mvc.ModelBinding.Metadata.DefaultModelMetadata { Attributes.PropertyAttributes.Count: > 0 } metadata && | ||
metadata.Attributes.PropertyAttributes.OfType<DescriptionAttribute>().LastOrDefault() is { } propertyDescription) | ||
{ | ||
return propertyDescription.Description; | ||
} | ||
Comment on lines
+505
to
+509
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure this is right, as it feels wrong to depend on a specific model metadata implementation, but I couldn't immediately see an obvious interface-y/abstract way to query the same information and this was "right there" in the debugger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for practical cases this is sufficient. The APIs will only ever end up consuming two metadata types:
The minimal API cases end up getting handled by the This is also why the bug reports that we've received specifically site this gap in controllers and not minimal APIs. So although it looks werid and is awakward, I think this is the correct way give the fact that MVC relies on model metadata and minimal API doesn't. |
||
|
||
return null; | ||
} | ||
|
||
private async Task<OpenApiRequestBody?> GetRequestBodyAsync(OpenApiDocument document, ApiDescription description, IServiceProvider scopedServiceProvider, IOpenApiSchemaTransformer[] schemaTransformers, CancellationToken cancellationToken) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -229,7 +229,7 @@ public ControllerActionDescriptor CreateActionDescriptor(string methodName = nul | |||
|
||||
action.AttributeRouteInfo = new() | ||||
{ | ||||
Template = action.MethodInfo.GetCustomAttribute<RouteAttribute>()?.Template, | ||||
Template = action.MethodInfo.GetCustomAttribute<RouteAttribute>()?.Template ?? string.Empty, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is to make this assertion happy:
|
||||
Name = action.MethodInfo.GetCustomAttribute<RouteAttribute>()?.Name, | ||||
Order = action.MethodInfo.GetCustomAttribute<RouteAttribute>()?.Order ?? 0, | ||||
}; | ||||
|
Uh oh!
There was an error while loading. Please reload this page.