Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swashbuckle.AspNetCore SwaggerOperation attribute not found

Tags:

I am trying to use Autorest and Swagger documentation created by the help of Swashbuckle.AspNetCore (3.0.0) in order to generate a REST API client.

The swagger documentation generated seems to be correct except that the operation name are not really nice.

"/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" } }       }, 

I saw in many articles and also on the official documentation of SwashBuckle.AspNetCore that I can use an attribute to decorate my controller method like this:

[HttpGet] [Produces("application/json")] [ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType(typeof(List<AddressDto>), (int)HttpStatusCode.OK)] [SwaggerOperation("GetAllAdresses")] public async Task<IActionResult> GetAllAsync() {    .... } 

Unfortunately, I got an error:

SwaggerOperationAttribute could not be found

I verified the NuGet packages installed and they are:

  • SwashBuckle.AspNetCore.Swagger (3.0.0)
  • SwashBuckle.AspNetCore.SwaggerGen (3.0.0)
  • SwashBuckle.AspNetCore.SwaggerUI (3.0.0)

How can I solve the problem?

like image 826
Sébastien Krejci Avatar asked Aug 22 '18 19:08

Sébastien Krejci


People also ask

What is SwaggerOperation attribute?

SwaggerOperation is a useful attribute where you can set the summary, description, id, and the tags of an individual request/route.

Which is embedded version of swagger UI tool?

In addition to its Swagger 2.0 and OpenAPI 3.0 generator, Swashbuckle also provides an embedded version of the awesome swagger-ui that's powered by the generated Swagger JSON. This means you can complement your API with living documentation that's always in sync with the latest code.


1 Answers

I ran across this today. I needed to add the following nuget package that was just added for V3.0.0:

Swashbuckle.AspNetCore.Annotations

Breaking changes are described here

Please also note that you need to add the following to Startup.cs or your Swagger extension:

AddSwaggerGen(c => { ... c.EnableAnnotations(); }) 
like image 63
ScottG Avatar answered Oct 19 '22 22:10

ScottG