使用以下代码,Swaggger UI将显示RegistrationInfo模型,但不会显示UserInfo模型。
我如何生成它?
[Produces("application/json")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api")]
public class UserController : Controller
{
[HttpPost("RegisterUser")]
public IActionResult RegisterUser([FromBody] RegistrationInfo info)
{
UserInfo data = UserData.RegisterUser(info);
if (data != null)
{
return Ok(data);
}
return NoContent();
}
}
答案 0 :(得分:2)
您需要使用ProducesResponseType
属性。将您的控制器更改为此:
[Produces("application/json")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[Route("api")]
public class UserController : Controller
{
[ProducesResponseType(typeof(UserInfo), StatusCodes.Status200OK)]
[HttpPost("RegisterUser")]
public IActionResult RegisterUser([FromBody] RegistrationInfo info)
{
UserInfo data = UserData.RegisterUser(info);
if (data != null)
{
return Ok(data);
}
return NoContent();
}
}
查看更多here。
希望这会有所帮助!