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)]
用于基于http代码的结果类型(即错误时返回不同的模型)[productsResponseType(typeof(CarInputModel),(int)HttpStatusCode.OK)]
用于路由本身[Route]
/// <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)]
用于基于http代码的结果类型(即错误时返回不同的模型)[productsResponseType(typeof(CarInputModel),(int)HttpStatusCode.OK)]
用于路由本身[Route]
/// <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; }
}
请阅读本帮助中心文章,了解如何正确使用标记以及为什么不应将标记强制设置为问题标题请阅读本帮助中心文章,了解如何正确使用标记以及为什么不应将标记强制设置为问题标题