2

I wish to generate OpenAPI Document using NSwag for my ASP.NET Controller methods, but with custom OpenAPI Extensions.

Example: Here's a part of my OpenAPI spec. I want to mention SLA of each path:

  /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'

Is it possible to add an attribute on the controller to achieve this through NSwag? If not, any suggestions to do this programmatically in ASP.NET Core?

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

Thanks!

Anas S
  • 43
  • 1
  • 9
  • See https://github.com/RicoSuter/NSwag/wiki/Document-Processors-and-Operation-Processors#operation-processors – Rico Suter Jun 07 '19 at 18:39
  • Or this: https://blog.rsuter.com/nswag-tutorial-implement-a-custom-operation-processor-to-define-redoc-code-samples/ – Rico Suter Jun 07 '19 at 18:43

0 Answers0