本文整理汇总了C#中System.Web.Http.Description.ApiDescription.GetRelativePathForSwagger方法的典型用法代码示例。如果您正苦于以下问题:C# ApiDescription.GetRelativePathForSwagger方法的具体用法?C# ApiDescription.GetRelativePathForSwagger怎么用?C# ApiDescription.GetRelativePathForSwagger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Description.ApiDescription
的用法示例。
在下文中一共展示了ApiDescription.GetRelativePathForSwagger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateApiDescriptions
protected void PopulateApiDescriptions(ODataActionDescriptor oDataActionDescriptor, List<ApiParameterDescription> parameterDescriptions, string apiDocumentation, List<ApiDescription> apiDescriptions)
{
Contract.Requires(oDataActionDescriptor != null);
Contract.Requires(apiDescriptions != null);
// request formatters
var bodyParameter = default(ApiParameterDescription);
if (parameterDescriptions != null)
{
bodyParameter = parameterDescriptions.FirstOrDefault(description => description.Source == ApiParameterSource.FromBody);
}
var httpConfiguration = oDataActionDescriptor.ActionDescriptor.Configuration;
Contract.Assume(httpConfiguration != null);
var mediaTypeFormatterCollection = httpConfiguration.Formatters;
var responseDescription = oDataActionDescriptor.ActionDescriptor.CreateResponseDescription();
IEnumerable<MediaTypeFormatter> supportedRequestBodyFormatters = new List<MediaTypeFormatter>();
IEnumerable<MediaTypeFormatter> supportedResponseFormatters = new List<MediaTypeFormatter>();
if (mediaTypeFormatterCollection != null)
{
supportedRequestBodyFormatters = bodyParameter != null ? mediaTypeFormatterCollection.Where(CanReadODataType(oDataActionDescriptor, bodyParameter)) : Enumerable.Empty<MediaTypeFormatter>();
// response formatters
var returnType = responseDescription.ResponseType ?? responseDescription.DeclaredType;
supportedResponseFormatters = returnType != null && returnType != typeof (void) ? mediaTypeFormatterCollection.Where(CanWriteODataType(oDataActionDescriptor, returnType)) : Enumerable.Empty<MediaTypeFormatter>();
// Replacing the formatter tracers with formatters if tracers are present.
supportedRequestBodyFormatters = GetInnerFormatters(supportedRequestBodyFormatters);
supportedResponseFormatters = GetInnerFormatters(supportedResponseFormatters);
}
var supportedHttpMethods = GetHttpMethodsSupportedByAction(oDataActionDescriptor.Route, oDataActionDescriptor.ActionDescriptor);
foreach (var supportedHttpMethod in supportedHttpMethods)
{
var apiDescription = new ApiDescription
{
Documentation = apiDocumentation,
HttpMethod = supportedHttpMethod,
RelativePath = oDataActionDescriptor.RelativePathTemplate.TrimStart('/'),
ActionDescriptor = oDataActionDescriptor.ActionDescriptor,
Route = oDataActionDescriptor.Route
};
var apiSupportedResponseFormatters = apiDescription.SupportedResponseFormatters;
Contract.Assume(apiSupportedResponseFormatters != null);
apiSupportedResponseFormatters.AddRange(supportedResponseFormatters);
var apiSupportedRequestBodyFormatters = apiDescription.SupportedRequestBodyFormatters;
Contract.Assume(apiSupportedRequestBodyFormatters != null);
apiSupportedRequestBodyFormatters.AddRange(supportedRequestBodyFormatters);
if (parameterDescriptions != null)
{
var apiParameterDescriptions = apiDescription.ParameterDescriptions;
Contract.Assume(apiParameterDescriptions != null);
apiParameterDescriptions.AddRange(parameterDescriptions);
}
// Have to set ResponseDescription because it's internal!??
apiDescription.SetInstanceProperty("ResponseDescription", responseDescription);
if (apiDescription.ParameterDescriptions != null)
{
apiDescription.RelativePath = apiDescription.GetRelativePathForSwagger();
}
apiDescriptions.Add(apiDescription);
}
}