- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我如何设置 Swagger operationId
Asp.Net Core 2.1 项目中的属性?根据 this我应该使用的帖子 SwaggerOperationAttribute
但我在 Swashbuckle.AspNetCore 库中找不到它。还有一个 IOperationFilter
public interface IOperationFilter
{
void Apply(Operation operation, OperationFilterContext context);
}
我找不到任何用于 swagger 生成目的的实现。
最佳答案
还有 2 个其他选项,而无需编写任何额外的代码或添加额外的依赖项,例如 Swashbuckle.AspNetCore.Annotations
选项 1 :基于约定 - SwaggerGen
可以选择设置 CustomOperationIds
.所以你可以简单地将它设置为使用 ControllerName_HttpMethod
像这样:
services.AddSwaggerGen(c =>
{
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["controller"]}_{e.HttpMethod}");
c.SwaggerDoc("v1", new Info { Title = "Test API", Version = "v1" });
});
这会将 operationIds 添加到您的所有方法中,遵循
ControllerName_HttpMethod
习俗。
SwaggerOperation
操作过滤器所做的一样,只需将
Name
属性添加到您的 HTTP 动词操作过滤器,如下所示:
[HttpPost(Name="Post_Person")]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public async Task<ActionResult<Response>> PostAsync([FromBody]Request request)
{
Response result = await _context.PostAsync(request);
return Ok(result);
}
这与
[SwaggerOperation(OperationId = "Post_Person")]
完全一样但不需要
EnableAnnotations
关于asp.net-core - Asp.Net 核心 Swashbuckle 设置 operationId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52262826/
我正在实现自定义 ApplicationInsights 记录器,并且能够在跟踪、异常和请求等写入位置写入所有日志,但跟踪和异常中的 OperationId 为空。 昨天我使用相同的代码并在所有表中获
我需要知道是否可以设置自定义 operationid 或命名约定,我的意思是我知道可以按照生成 operationId 的方式覆盖操作过滤器 https://azure.microsoft.com/e
我正在使用 AutoRest 从 swagger.json 生成 api 的客户端 输出是 AutoRest code generation utility [cli version: 3.0.618
我正在使用 Swagger 记录我的 Django API。当我生成我的 Openapi 架构时,为我的每个路径添加了带有附加参数 {format} 的第二条路由,具有相同的操作 ID作为“正确”路线
当我尝试使用 gcloud service-management deploy openapi.json 部署我的 Cloud Endpoints Framework api 时,我收到许多类似于以下
我的问题是: 在我的场景中注入(inject)自定义关联/操作 ID 的正确/更好的方法是什么,该方法不会导致内存泄漏,并且可以正确使用并显示在 Azure 门户上? 以下是我的场景的具体细节: 我有
我正在使用 aspnet core 2.2 创建 Restful API。我有一个标准设置,其中每个模型都有自己的 Controller ,带有 GET 和 POST 操作。我正在使用 Swashbu
在为现有的 500 多个 Controller 和相应方法创建 Angular API 服务代理时,我们试图覆盖 Swashbuckle/Swagger IO CodeGen 命名约定。 目前正在将
我如何设置 Swagger operationId Asp.Net Core 2.1 项目中的属性?根据 this我应该使用的帖子 SwaggerOperationAttribute但我在 Swash
我是一名优秀的程序员,十分优秀!