Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// New code //
[AttributeUsage(AttributeTargets.Method)]
public class MyParameterAttribute : Attribute
{
public string Name { get; set; }
public string Documentation { get; set; }
public ApiParameterSource Source { get; set; }
}
public class MyHttpParameterDescriptor : HttpParameterDescriptor
{
public Type MyParameterType { get; set; }
public MyHttpParameterDescriptor(Type type)
{
MyParameterType = type;
}
public override string ParameterName
{
get { return ""; }
}
public override Type ParameterType
{
get { return MyParameterType; }
}
}
//////////////
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "The exception is recorded as ErrorMessages.")]
private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HelpPageSampleGenerator sampleGenerator)
{
HelpPageApiModel apiModel = new HelpPageApiModel();
apiModel.ApiDescription = apiDescription;
// New code //
MyParameterAttribute customAttribute = apiDescription.ActionDescriptor.GetCustomAttributes<MyParameterAttribute>().FirstOrDefault();
if (customAttribute != null)
{
apiDescription.ParameterDescriptions.Add(new ApiParameterDescription
{
Name = customAttribute.Name,
Documentation = customAttribute.Documentation,
Source = customAttribute.Source,
ParameterDescriptor = new MyHttpParameterDescriptor(typeof(File))
});
}
//////////////
try
{
foreach (var item in sampleGenerator.GetSampleRequests(apiDescription))
{
apiModel.SampleRequests.Add(item.Key, item.Value);
LogInvalidSampleAsError(apiModel, item.Value);
}
foreach (var item in sampleGenerator.GetSampleResponses(apiDescription))
{
apiModel.SampleResponses.Add(item.Key, item.Value);
LogInvalidSampleAsError(apiModel, item.Value);
}
}
catch (Exception e)
{
apiModel.ErrorMessages.Add(String.Format(CultureInfo.CurrentCulture, "An exception has occurred while generating the sample. Exception Message: {0}", e.Message));
}
return apiModel;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.