2016-12-22 19 views
0

在該方法中表明需要複雜的輸入參數對象的屬性在揚鞭UI

/// <summary> 
     /// Gets activity logs. 
     /// </summary> 
     /// <param name="locationId">Location id.</param> 
     /// <param name="filter">Activity log filter options.</param> 
     /// <response code="200">OK</response> 
     [ResponseType(typeof(ActivityLogResponse))] 
    public async Task<HttpResponseMessage> FetchActivityLogs(int locationId, ActivityLogFilterOptions filter) 
        { 
      } 

ActivityLogFilterOptions有一些要求的特性和一些是可選的。有沒有什麼方法可以在Swagger UI API參數中指出這一點?

ActivityLogFilterOptions類:

/// <summary> 
    /// Represents an activity log filter options. 
    /// </summary> 
    public class ActivityLogFilterOptions 
    { 
     /// <summary> 
     /// Gets or sets the device ids to which the activity logs to be fetched. 
     /// </summary> 
     public string DeviceIds { get; set; } 

     /// <summary> 
     /// Gets or sets the start date for of the search. 
     /// </summary> 
     [DateTimeCompare("ToDate", 
      ValueComparison.IsLessThan, ErrorMessage = "From date must be earlier than end date.")] 
     public DateTime? FromDate { get; set; } 

     /// <summary> 
     /// Gets or sets the end date for the search. 
     /// </summary> 
     [DateTimeCompare("FromDate", 
      ValueComparison.IsGreaterThan, ErrorMessage = "To date must be later than from date.")] 
     public DateTime? ToDate { get; set; } 

     /// <summary> 
     /// Gets or set the page index. 
     /// </summary> 
     [Required] 
     [Range(0, int.MaxValue)] 
     public int? PageIndex { get; set; } 

     /// <summary> 
     /// Gets or sets the maximum record count per page. 
     /// </summary> 
     [Required] 
     [Range(1, short.MaxValue)] 
     public int? RecordsPerPage { get; set; } 

     /// <summary> 
     /// Gets or sets the activity log groups. 
     /// </summary> 
     public string Groups { get; set; } 
    } 

enter image description here

回答

1

是的,如果你裝飾用RequiredAttribute則該屬性不會在揚鞭UI顯示爲「可選」的API模型的屬性:

[Required] 
[JsonProperty(PropertyName = "your_property")] 
public string YourProperty {get; set;} 

對於複雜的物體,您可以通過單擊「模型」鼠標來查看模型上屬性的可選性她比「參數」部分的「數據類型」列中的「示例值」更大。

+0

如果'YourProperty'是我的API的直接參數,但在我的情況下ActivityLogFilterOptions是輸入參數,並且ActivityLogFilterOptions的其中一個屬性是可選的。 – JerryGoyal

+0

您可以通過單擊「參數」部分的「數據類型」列中的「模型」而不是「示例值」來查看模型上屬性的可選性。 – strickt01

+0

嘿,工作!我太傻了。 – JerryGoyal