- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Swashbuckle.AspNetCore.SwaggerGen.IDocumentFilter
它在我的 swagger 配置文件中的路径级别添加了 x-summary 值。为此,它需要访问每个 Web 方法的以下两条信息
context
中获得 #1和来自
swaggerDoc
的 #2提供给 IDocumentFilter 实现,但除了使用路径之外,我找不到链接它们的好方法。
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
// Create a map from path (prepended with "/") to the custom attribute
var methodsByPath = context.ApiDescriptions
.ToDictionary(
m => $"/{m.RelativePath}",
m => ((ControllerActionDescriptor)m.ActionDescriptor).MethodInfo.GetCustomAttribute<MyCustomAttribute>());
// Add x-summary to each path
foreach (var pathItem in swaggerDoc.Paths)
{
var customAttribute = methodsByPath[pathItem.Key];
pathItem.Value.Extensions["x-summary"]
= GeneratePathDescription(pathItem.Value.Post.Summary, customAttribute);
}
}
string GeneratePathDescription(string methodSummary, MyCustomAttribute attr)
{
[snip]
}
最佳答案
您的实现对我来说看起来很整洁,但是如果您正在寻找有关如何在 Swashbuckle 的代码中“最佳”实现 IDocumentFilter 外观的示例:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/e2f30e04f412b821a5a989338a186e422c776cc4/src/Swashbuckle.AspNetCore.Annotations/AnnotationsDocumentFilter.cs
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b64b8fd6fbc7959849445be676f5e3d4a8e947bf/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsDocumentFilter.cs
关于c# - Swashbuckle IDocumentFilter 实现 - 如何将 ActionDescriptor.MethodInfo 链接到操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59569007/
ActionExecutedContext 类中是否有类似ActionExecutingContext 的ActionDescriptor.ActionParameters 属性的东西? 我需要在这个
鉴于我只能访问 ControllerContext 而不能访问 Action____Contexts 获取当前正在执行的 ActionDescriptor 的最佳方法是什么? 到目前为止,我找到的唯一
我如何从 MessageHandler 中检索 ActionDescriptor? 我可以使用以下代码在 SendAsync 方法中获取 ContractDescriptor: var config
我在 Jira 项目的私有(private) Atlassian 插件之一中找到了它。 import com.opensymphony.workflow.loader.ActionDescriptor
正如您在下面看到的,在我的 ActionFilter 中,我尝试获取 ActionExecutingContext.ActionDescriptor 的 ActionName 和 MethodInfo
我正在尝试为使用属性路由 的 Controller 上的操作获取ActionDescriptor,但它始终为空。 var controllerDescriptor = new ReflectedCon
跟进Authorization Filter Dependency Injection with ASP.New MVC 4 Web Api .有没有办法在所有 Controller 类上全局设置的过
项目:ASP Net Core 2.2、Web API 包:Swashbuckle.AspNetCore (4.0.1) 我正在写一个实现 Swashbuckle.AspNetCore.Swagger
我的应用程序上有一个 ActionFilterAttribute,用于在检测到用户未通过身份验证时重定向用户。在过滤器中,我想检测操作的 ReturnType 何时为 JsonResult。 作为解决
给定 Action 名称、 Controller 名称和 HTTP 动词(GET、POST .. 等),是否可以检查 Action 是否具有(即由)特定 Action 过滤器属性? 请注意: Acti
我是一名优秀的程序员,十分优秀!