我正在尝试使用由Swashbuckle.AspNetCore (3.0.0)创建的Autorest和Swagger文档来生成REST API客户端。
生成的swagger文档似乎是正确的,除了操作名称并不是很好。
"/api/Addresses/{id}": {
"get": {
"tags": [ "Address" ],
"operationId": "ApiAddressesByIdGet",
"consumes": [],
"produces": [],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
"format": "uuid"
}
],
"responses": { "200": { "description": "Success" } }
},我在许多文章和SwashBuckle.AspNetCore的官方文档中看到,我可以使用属性来修饰我的控制器方法,如下所示:
[HttpGet]
[Produces("application/json")]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(List<AddressDto>), (int)HttpStatusCode.OK)]
[SwaggerOperation("GetAllAdresses")]
public async Task<IActionResult> GetAllAsync()
{
....
}不幸的是,我得到了一个错误:
找不到
SwaggerOperationAttribute
我验证了安装的NuGet包,它们是:
我该如何解决这个问题?
发布于 2018-08-23 04:12:08
我今天遇到了这个。我需要添加以下nuget包,该包是刚刚为v3.0.0添加的:
Swashbuckle.AspNetCore.Annotations
here描述了突破性的变化
还请注意,您需要将以下内容添加到Startup.cs或Swagger扩展中:
AddSwaggerGen(c => { ... c.EnableAnnotations(); })发布于 2019-01-22 01:14:48
另一种选择是为HttpGet过滤器设置Name属性,如下所示:
[HttpGet(Name = "GetAllAdresses")]
[Produces("application/json")]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(List<AddressDto>), (int)HttpStatusCode.OK)]
[SwaggerOperation("GetAllAdresses")]
public async Task<IActionResult> GetAllAsync()
{
....
}https://stackoverflow.com/questions/51974264
复制相似问题