Asp.net core 虚张声势:如何显示模型参数数组的类型?
我正在使用的最新2.4版本为具有两个参数的AspNetCore控制器方法生成文档:guid和模型列表Asp.net core 虚张声势:如何显示模型参数数组的类型?,asp.net-core,swagger,swashbuckle,Asp.net Core,Swagger,Swashbuckle,我正在使用的最新2.4版本为具有两个参数的AspNetCore控制器方法生成文档:guid和模型列表 [HttpPost("MyMethod/{ReferenceId}")] public async Task<IActionResult> MyMethod(Guid referenceId, List<ApiProfile> passengers) 在json中: "parameters": [ { "name": "passengers",
[HttpPost("MyMethod/{ReferenceId}")]
public async Task<IActionResult> MyMethod(Guid referenceId, List<ApiProfile> passengers)
在json中:
"parameters": [
{
"name": "passengers",
"in": "query",
"description": "",
"required": false,
"type": "array",
"items": {},
"collectionFormat": "multi"
},
"definitions": {
"ApiProfile": {
"description": "API Object",
"type": "object",
"properties": {"Id": {"format": "uuid","type": "string"},
"Email": {"type": "string"},
"salutation": {"type": "string"},
"firstName": {"type": "string"}
...
请注意,型号剖面显示在“型号”部分的底部:
ApiProfile {
description: API Object
Id string($uuid)
Email string
salutation string
firstName string
lastName string
dateOfBirth string($date-time)
}
在json中:
"parameters": [
{
"name": "passengers",
"in": "query",
"description": "",
"required": false,
"type": "array",
"items": {},
"collectionFormat": "multi"
},
"definitions": {
"ApiProfile": {
"description": "API Object",
"type": "object",
"properties": {"Id": {"format": "uuid","type": "string"},
"Email": {"type": "string"},
"salutation": {"type": "string"},
"firstName": {"type": "string"}
...
我需要一个建议,如何描述要在Swagger UI中显示的请求参数列表的类型
我尝试分配[SwaggerRequestExample(typeof(PeopleRequest),typeof(ListPeopleRequestExample))],但不确定如何使用2个参数。
我还尝试暂时排除第一个参数,但有相同的行为
[Route("[controller]")]
public class SwashbuckleTest : Controller
{
[HttpPost]
[Route("{id}")]
public SwashbuckleTestProfile Post(Guid id, List<SwashbuckleTestProfile> companies)
{
return companies.FirstOrDefault();
}
}
public class SwashbuckleTestProfile
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
更新:我已经创建了一个最小版本,但具有相同的行为
[Route("[controller]")]
public class SwashbuckleTest : Controller
{
[HttpPost]
[Route("{id}")]
public SwashbuckleTestProfile Post(Guid id, List<SwashbuckleTestProfile> companies)
{
return companies.FirstOrDefault();
}
}
public class SwashbuckleTestProfile
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
[路由(“[控制器]”)]
公共类SwashbuckleTest:控制器
{
[HttpPost]
[路由(“{id}”)]
公共SwashbuckleTestProfile帖子(Guid id,上市公司)
{
返回公司。FirstOrDefault();
}
}
公共类虚张声势公司
{
公共字符串电子邮件{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
}
完整的示例可以从加载,您不需要做任何特殊的事情或描述任何事情
虚张声势的人应该注意这个。。。 闻起来像虫子 我用我的项目Swagger Net测试了一些类似的东西,结果显示正常:
[路由(“{id}”)]
上市公司职位(Guid id,上市公司)
{
返回公司。FirstOrDefault();
}
以下是代码输出的相关JSON:
{
“名称”:“公司”,
“in”:“body”,
“必需”:正确,
“模式”:{
“项目”:{
$ref:“#/定义/公司”
},
“xml”:{
“名称”:“公司”,
“包装”:正确
},
“类型”:“数组”
}
}
我想如果你真的想获得虚张声势,你可以使用IDocumentFilter,并将模式更改为更像我的模式
更新:在使用提供的最低版本后,添加[FromBody]
似乎对Swashback.AspNetCore中的模式进行了重大更改
[路由(“{id}”)]
上市公司职位(Guid id,[FromBody]上市公司)
您使用的是哪个版本的Swashback?我已经创建了一个最小版本(请参见问题更新),但运气不好。我正在使用我自己的项目Swagger Net:u但我仍然没有创建Net core版本库。如果是虚张声势中的错误,我会向them@MichaelFreidgeim查看我的更新。。。尝试添加[FromBody]谢谢,这很有帮助。我还把它报告为一个bug