Using Swashbuckle for Asp.net core how can I add a model to the generated model list?

后端 未结 4 1395
耶瑟儿~
耶瑟儿~ 2021-02-02 15:35

I\'m using Swashbuckle with ASP.net core. It is producing a nice website with a list of models at the bottom.

How can I add a model to this list that isn\'t al

4条回答
  •  醉酒成梦
    2021-02-02 16:10

    In retrospect, the other answer that I found below (and on other pages) was better, namely to add this kind of attribute:

    [HttpGet("")]
    [ProducesResponseType(typeof(MyResult), (int)System.Net.HttpStatusCode.OK)]
    [ProducesResponseType(typeof(ErrorBase), (int)System.Net.HttpStatusCode.NotFound)]
    ... function definition ...
    

    Why: because the function gives different types of objects based on different situations and with these attributes you can specify which objects are returned in which situation.

    For example I can give back

    return Ok(myresult)
    

    or

    return NotFound(myerror)
    

    in my function based on whether I've found a result or not.

提交回复
热议问题