c# - Nswag 在相同的 Http 状态代码中指定多个响应示例?
问题描述
我需要通过 C# 设置一些具有相同 http 状态代码的响应示例。
但我还是不知道。
我能怎么做 ?
请给我一些提示...
// 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(){
}
解决方案
你可以这样的SwaggerResponse
属性:
[HttpGet("")]
[SwaggerResponse(200, "Myfile content", typeof(MyFile))]
[SwaggerResponse(404, "Could not find file", typeof(MyFile))]
public async Task<IActionResult> YouAction()
它将记录 2 个可能的响应状态代码:200
和404
. 您可以根据需要应用任意数量的这些属性
推荐阅读
- android - java.lang.RuntimeException:无法获取提供者 mono.android.MultiDexLoader
- ssis - Kingswaysoft SSIS 创建联系人慢
- oracle - Oracle 12c 的默认登录密码是什么?
- neural-network - 为我的 CNN 选择最佳池化类型
- macos - 以编程方式将 Web 应用程序快捷方式添加到 macOS Dock
- c# - 使用 ModelStoreConatiner 名称作为 Schema 对特定表查询 db 的 EF 查询
- assembly - 我应该使用哪个汇编程序在 dosbox 中编译此代码
- javascript - 需要帮助在函数中更改 SVG 的颜色 - Skycons
- node.js - 在 QueryFile 中进行多次插入
- spring - Spring Batch 如何执行 Skip 或不考虑编写?