本文介绍了Swashbuckle-返回的响应的草率文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swashbuckle不会生成带有"UserCreateResponse"输出的swagger.json,如何解决此问题?

Swashbuckle would not generate swagger.json with an output of "UserCreateResponse", how do you fix this?

    [HttpPost]
    public async Task<IActionResult> Update([FromBody]UserCreate Request)
    {
        UserCreateResponse response = new UserCreateResponse();

        //do something here

        // returns UserCreateResponse with http status code 200
        return Ok(response);
    }

您无法执行此操作,因为它不会返回http状态码200,400,401等

You can't do this, because its not going to return the http status code, 200,400,401 etc

    [HttpPost]
    public async Task<UserCreateResponse> Update([FromBody]UserCreate Request)
    {
        UserCreateResponse response = new UserCreateResponse();

        //do something here

        // returns UserCreateResponse
        return response;
    }

推荐答案

您可以使用以下属性指定响应类型:

You can specify the response type with the following attribute:

[ProducesResponseType(typeof(UserCreateResponse), 200)]

这篇关于Swashbuckle-返回的响应的草率文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 19:48