Swashbuckle adds a 200 OK response automatically to the generated Swagger file

I am creating documents for swagger using Swashbuckle in my WebApi 2 project.

I have the following method definition:

[HttpPost] [ResponseType(typeof(Reservation))] [Route("reservations")] [SwaggerResponse(HttpStatusCode.Created, Type = typeof(Reservation))] [SwaggerResponse(HttpStatusCode.BadRequest) ] [SwaggerResponse(HttpStatusCode.Conflict)] [SwaggerResponse(HttpStatusCode.NotFound)] [SwaggerResponse(HttpStatusCode.InternalServerError)] public async Task<HttpResponseMessage> ReserveTickets([FromBody] ReserveTicketsRequest reserveTicketRequest) { // ... return Request.CreateResponse(HttpStatusCode.Created, response); } 

However, the generated Swagger file contains HTTP 200 OK, although it is not specified anywhere.

 /reservations: post: tags: - "Booking" operationId: "Booking_ReserveTickets" consumes: - "application/json" - "text/json" produces: - "application/json" - "text/json" parameters: - name: "reserveTicketRequest" in: "body" required: true schema: $ref: "#/definitions/ReserveTicketsRequest" responses: 200: description: "OK" schema: $ref: "#/definitions/Reservation" 201: description: "Created" schema: $ref: "#/definitions/Reservation" 400: description: "BadRequest" 404: description: "NotFound" 409: description: "Conflict" 500: description: "InternalServerError" deprecated: false 

Is there any way to get rid of this 200 OK? This is confusing as it is not a valid answer.

Thanks for the suggestions.

+7
c # swagger swashbuckle
source share
1 answer

You can remove the default response (200 OK) by decorating the method with the SwaggerResponseRemoveDefaults attribute.

+9
source share

All Articles