查看属性 (SwaggerExample) 采用两个参数的代码:
public SwaggerExampleAttribute(string parameterName, object example)
{
this.ParameterName = parameterName;
this.Example = example;
}
https://github.com/heldersepu/Swagger-Net/blob/6afdb0c1ba611273f27e8a904ec2bb06a630b1b4/Swagger.Net/Swagger/Annotations/SwaggerExampleAttribute.cs#L16
我们可以看到第一个是字符串,但第二个是对象......
理论上你应该可以在那里传递任何东西。
我会推荐另一种选择,如果您有像您这样的复杂模型,Thing
您应该考虑在模型上添加示例,我们可以在那里做更多的事情......正如您在下面看到的,我们可以添加描述、示例值和其他一些装饰器我们可以限制值的范围,代码如下:
/// <summary>
/// ## Geographic coordinates
/// ___
/// A **geographic coordinate system** is a coordinate system used in geography that enables every location on Earth to be specified by a set of numbers
/// </summary>
public class Location
{
/// <summary>**Latitude**: a geographic coordinate that specifies the north–south position of a point on the Earth's surface.</summary>
/// <example>25.85</example>
[Range(-90, 90)]
public float Lat { get; set; }
/// <summary>**Longitude**: a geographic coordinate that specifies the east-west position of a point on the Earth's surface.</summary>
/// <example>-80.27</example>
[Range(-180, 180)]
public float Lon { get; set; }
}
http://swagger-net-test.azurewebsites.net/swagger/ui/index#/Location/Location_Get2