using System.Collections.Generic; using System.Collections.ObjectModel; using System.Net.Http.Headers; using System.Web.Http.Description; using Authentication_test.Areas.HelpPage.ModelDescriptions; namespace Authentication_test.Areas.HelpPage.Models { /// /// The model that represents an API displayed on the help page. /// public class HelpPageApiModel { /// /// Initializes a new instance of the class. /// public HelpPageApiModel() { UriParameters = new Collection(); SampleRequests = new Dictionary(); SampleResponses = new Dictionary(); ErrorMessages = new Collection(); } /// /// Gets or sets the that describes the API. /// public ApiDescription ApiDescription { get; set; } /// /// Gets or sets the collection that describes the URI parameters for the API. /// public Collection UriParameters { get; private set; } /// /// Gets or sets the documentation for the request. /// public string RequestDocumentation { get; set; } /// /// Gets or sets the that describes the request body. /// public ModelDescription RequestModelDescription { get; set; } /// /// Gets the request body parameter descriptions. /// public IList RequestBodyParameters { get { return GetParameterDescriptions(RequestModelDescription); } } /// /// Gets or sets the that describes the resource. /// public ModelDescription ResourceDescription { get; set; } /// /// Gets the resource property descriptions. /// public IList ResourceProperties { get { return GetParameterDescriptions(ResourceDescription); } } /// /// Gets the sample requests associated with the API. /// public IDictionary SampleRequests { get; private set; } /// /// Gets the sample responses associated with the API. /// public IDictionary SampleResponses { get; private set; } /// /// Gets the error messages associated with this model. /// public Collection ErrorMessages { get; private set; } private static IList GetParameterDescriptions(ModelDescription modelDescription) { ComplexTypeModelDescription complexTypeModelDescription = modelDescription as ComplexTypeModelDescription; if (complexTypeModelDescription != null) { return complexTypeModelDescription.Properties; } CollectionModelDescription collectionModelDescription = modelDescription as CollectionModelDescription; if (collectionModelDescription != null) { complexTypeModelDescription = collectionModelDescription.ElementDescription as ComplexTypeModelDescription; if (complexTypeModelDescription != null) { return complexTypeModelDescription.Properties; } } return null; } } }