如何在ASP.NET Core中为Controller方法添加属性以生成OpenAPI扩展

时间:2019-06-06 21:58:33

标签: c# asp.net-core openapi nswag

我希望使用NSwag为我的ASP.NET Controller方法生成OpenAPI文档,但要使用自定义OpenAPI Extensions

示例:这是我的OpenAPI规范的一部分。我想提到每个路径的SLA:

  /v1/address/verifyAddress:
    put:
      summary: Verify address
      operationId: verifyAddress
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          required: false
          schema:
            $ref: '#/definitions/Address'
      responses:
        '200':
          description: successful operation
          schema:
            type: array
            items:
              $ref: '#/definitions/Address'
      x-sla:
        responseTime: '100'
        availability: '85'
        requestsPerSecond: '50'

是否可以在控制器上添加属性以通过NSwag实现此目的?如果没有,在ASP.NET Core中以编程方式执行此操作的任何建议?

[HttpPut]
[Route("verifyAddress")]
[ProducesResponseType(typeof(ApiDetailsModel), statusCode: 200)]
[SwaggerOperation("validateAddress")]
public async Task<IActionResult> VerifyAddress([FromBody] AddressModel model)
{}

谢谢!

0 个答案:

没有答案