WebSpi中使用Swashbuckle和NSwag的代码生成复杂输入参数

问题描述

我正在使用Swashbuckle 5.6生成OpenAPI规范,并使用Nswag 13.7.3生成c#客户端和模型。我想知道当前是否可以通过这种控制器(带有查询参数的GET)生成客户端方法

public class TestController
{
    [HttpGet]
    public string GetComplex([FromQuery] ComplexType input )..
}

public class ComplexType
{
    public string Name {get; set;}
    public int Age {get; set;}
}

致此客户

public class Client
{
    public string GetComplex(ComplexType type)...  
}

代替

public class Client
{
    public string GeComplex(strung name,int age)..
}

解决方法

我想知道当前是否可以从这种控制器(带有查询参数的GET)生成客户端方法

是的,这是模型绑定的默认行为。我使用您的代码进行了测试。

enter image description here

官方教程链接:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...