小编Vác*_*uša的帖子

Swashbuckle自动向生成的Swagger文件添加200 OK响应

我在WebApi 2项目中使用Swashbuckle构建swagger文档.

我有以下方法的定义:

[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);
}
Run Code Online (Sandbox Code Playgroud)

但是,生成的Swagger文件也包含HTTP 200 OK,尽管它没有在任何地方指定.

/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: …
Run Code Online (Sandbox Code Playgroud)

c# swagger swashbuckle

9
推荐指数
1
解决办法
3446
查看次数

标签 统计

c# ×1

swagger ×1

swashbuckle ×1