Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用招摇过市尽可能多地描述输入模型_C#_Asp.net Core_Swagger_Swagger Ui - Fatal编程技术网

C# 如何用招摇过市尽可能多地描述输入模型

C# 如何用招摇过市尽可能多地描述输入模型,c#,asp.net-core,swagger,swagger-ui,C#,Asp.net Core,Swagger,Swagger Ui,我有一个输入模型示例,如下所示: public class CarInputModel { public string Name { get; set; } public string ModelName { get; set; } } 这些值将来自UI,我可以使用什么样的注释与swagger一起尽可能多地描述此API模型?您根本不能使用许多注释来描述模型。您主要描述API本身 http属性的[HttpGet]和[HttpPost] [products(typeof(CarI

我有一个输入模型示例,如下所示:

public class CarInputModel {
    public string Name { get; set; }
    public string ModelName { get; set; }
}

这些值将来自UI,我可以使用什么样的注释与swagger一起尽可能多地描述此API模型?

您根本不能使用许多注释来描述模型。您主要描述API本身

  • http属性的
    [HttpGet]
    [HttpPost]
  • [products(typeof(CarInputModel)]
    用于操作的返回类型,
    [productsResponseType(typeof(CarInputModel),(int)HttpStatusCode.OK)]
    用于基于http代码的结果类型(即错误时返回不同的模型)
  • [Route]
    用于路由本身
此外,还可以使用Xml文档描述类及其参数

/// <summary>
/// Adds a new car model.
/// </summary>
/// <param name="model">The model to add</param>
/// <response code="201">Returns when the car was added successfully and returns the location to the new resource</response>
/// <response code="400">Invalid Request data.</response>
/// <response code="409">Car mode already exists.</response>
/// <returns>The newly added model on success and a list of errors on failure.</returns>
[HttpPost]
[ProducesResponseType(typeof(CarInputModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(SerializableError), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(void), (int)HttpStatusCode.Conflict)]
public IActionResult AddCar(CarInputModel model) 
{
}

/// <summary>
/// Represents a car
/// </summary>
public class CarInputModel {
    /// <summary>
    /// Name of the car
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// Model of the car
    /// </summary>
    public string ModelName { get; set; }
}

您根本不能使用很多注释来描述模型,您主要描述的是API本身

  • http属性的
    [HttpGet]
    [HttpPost]
  • [products(typeof(CarInputModel)]
    用于操作的返回类型,
    [productsResponseType(typeof(CarInputModel),(int)HttpStatusCode.OK)]
    用于基于http代码的结果类型(即错误时返回不同的模型)
  • [Route]
    用于路由本身
此外,还可以使用Xml文档描述类及其参数

/// <summary>
/// Adds a new car model.
/// </summary>
/// <param name="model">The model to add</param>
/// <response code="201">Returns when the car was added successfully and returns the location to the new resource</response>
/// <response code="400">Invalid Request data.</response>
/// <response code="409">Car mode already exists.</response>
/// <returns>The newly added model on success and a list of errors on failure.</returns>
[HttpPost]
[ProducesResponseType(typeof(CarInputModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(SerializableError), (int)HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(void), (int)HttpStatusCode.Conflict)]
public IActionResult AddCar(CarInputModel model) 
{
}

/// <summary>
/// Represents a car
/// </summary>
public class CarInputModel {
    /// <summary>
    /// Name of the car
    /// </summary>
    public string Name { get; set; }
    /// <summary>
    /// Model of the car
    /// </summary>
    public string ModelName { get; set; }
}
请阅读本帮助中心文章,了解如何正确使用标记以及为什么不应将标记强制设置为问题标题请阅读本帮助中心文章,了解如何正确使用标记以及为什么不应将标记强制设置为问题标题