Nswag在相同的Http状态代码中指定多个响应示例吗?

问题描述 投票:1回答:1

我需要设置一些响应示例,这些示例的C#具有相同的http状态代码。

我已经研究过该职位https://blog.rsuter.com/nswag-tutorial-implement-a-custom-operation-processor-to-define-redoc-code-samples/

但是我还是不知道。

我该怎么办?请给我一些提示...

// i want to create json , like this.
responses:
        '404':
          description: please , let It worked...
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestModel'
              examples:
                success :
                  summary: Example of a successful response
                  value:
                    code : 1
                    message : "test message 1"
                success2 :
                  summary: Example of a successful response2
                  value:
                    code : 2
                    message: "test message 2"

更新:我像这样使用NSwag我需要让代码404有两个示例响应

/// <summary></summary>
/// <remarks></remarks>
/// <response code="200"></response>
/// <response code="404">Message 1</response>
/// <response code="404">Message 2</response>   // <---- error will occur , 
[HttpPost]
[ProducesResponseType(typeof(CreateIdentificationResponse), 200)]
[ProducesResponseType(typeof(ErrorResponse), 404)]
[ProducesResponseType(typeof(ErrorResponse), 404)]
public IActionResult Post(){
}
c# swagger swagger-ui nswag redoc
1个回答
0
投票

您可以像这样[SwaggerResponse属性:

[HttpGet("")]
[SwaggerResponse(200, "Myfile content", typeof(MyFile))]
[SwaggerResponse(404, "Could not find file", typeof(MyFile))]
public async Task<IActionResult> YouAction()

它将记录2种可能的响应状态代码:200404。您可以根据需要应用任意多个属性

© www.soinside.com 2019 - 2024. All rights reserved.