本文整理汇总了C#中System.Web.Http.Description.ApiDescription类的典型用法代码示例。如果您正苦于以下问题:C# ApiDescription类的具体用法?C# ApiDescription怎么用?C# ApiDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiDescription类属于System.Web.Http.Description命名空间,在下文中一共展示了ApiDescription类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GenerateApiModel
public static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HelpPageSampleGenerator sampleGenerator)
{
HelpPageApiModel apiModel = new HelpPageApiModel();
apiModel.ApiDescription = apiDescription;
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;
}
开发者ID:geekcubed,项目名称:webapi-html-help-generation,代码行数:26,代码来源:HelpPageConfigurationExtensions.cs
示例2: Generate
public static MetadataPlainObjects.Fields Generate(MappingRule mappingRule, ApiDescription apiDescription, object originalObject)
{
var fromBodyParameterType = (from param in mappingRule.MethodExpression.Method.GetParameters()
let fromBodyAttr = param.GetCustomAttribute<FromBodyAttribute>()
where fromBodyAttr != null
select param.ParameterType).FirstOrDefault();
if (fromBodyParameterType == null)
return GenerateFromGet(mappingRule, apiDescription, originalObject);
var result = new MetadataPlainObjects.Fields();
result.AddRange(from property in fromBodyParameterType.GetProperties()
let fieldName = GetFieldName(property)
let propVal = property.GetValue(originalObject)
let jsonIgnore = property.GetCustomAttribute<JsonIgnoreAttribute>()
where jsonIgnore == null
select new MetadataPlainObjects.Field
{
FieldName = fieldName,
FieldType = GetFieldType(property),
FieldValue = propVal == null ? null : propVal.ToString()
});
return result;
}
开发者ID:RichieYang,项目名称:NHateoas,代码行数:25,代码来源:ActionFieldsGenerator.cs
示例3: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (!operation.responses.ContainsKey("default") && operation.responses.ContainsKey("200"))
{
operation.responses.Add("default", operation.responses["200"]);
}
}
开发者ID:drandysip,项目名称:DarlInference,代码行数:7,代码来源:AddDefaultResponse.cs
示例4: VersionSupportByAttribute
private static bool VersionSupportByAttribute(ApiDescription apiDesc, string version)
{
var attr = apiDesc.ActionDescriptor.GetCustomAttributes<SupportedInVersionsAttribute>().FirstOrDefault();
if (attr == null) return false;
return attr.Versions.Contains(version);
}
开发者ID:rodrigograudo,项目名称:Swashbuckle,代码行数:7,代码来源:SwaggerConfig.cs
示例5: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.operationId == "FileDownload_GetFile")
{
operation.produces = new[] { "application/octet-stream" };
}
}
开发者ID:BenjaminAdams,项目名称:Swashbuckle-blue,代码行数:7,代码来源:UpdateFileDownloadOperations.cs
示例6: CreateOperation
private Operation CreateOperation(ApiDescription apiDescription, SchemaRegistry schemaRegistry)
{
var parameters = apiDescription.ParameterDescriptions
.Select(paramDesc =>
{
var inPath = apiDescription.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}");
return CreateParameter(paramDesc, inPath, schemaRegistry);
})
.ToList();
var responses = new Dictionary<string, Response>();
var responseType = apiDescription.ResponseType();
if (responseType == null || responseType == typeof(void))
responses.Add("204", new Response { description = "No Content" });
else
responses.Add("200", new Response { description = "OK", schema = schemaRegistry.GetOrRegister(responseType) });
var operation = new Operation
{
tags = new [] { _options.GroupingKeySelector(apiDescription) },
operationId = apiDescription.FriendlyId(),
produces = apiDescription.Produces().ToList(),
consumes = apiDescription.Consumes().ToList(),
parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
responses = responses,
deprecated = apiDescription.IsObsolete()
};
foreach (var filter in _options.OperationFilters)
{
filter.Apply(operation, schemaRegistry, apiDescription);
}
return operation;
}
开发者ID:partychen,项目名称:Swashbuckle,代码行数:35,代码来源:SwaggerGenerator.cs
示例7: ApiResource
public ApiResource(ApiDescription description)
{
this.Url = this.EnsureStartingSlash(description.RelativePath);
this.HttpMethod = description.HttpMethod.Method.ToLower();
this.Name = this.EnsureLowerFirstLetter(description.ActionDescriptor.ActionName);
this.ParamsFromQueryString = this.GetParamsFromQueryString(description.ActionDescriptor.GetParameters());
}
开发者ID:mbgreen,项目名称:WebApiScriptProxy,代码行数:7,代码来源:ApiResource.cs
示例8: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters == null) return;
HandleFromUriArrayParams(operation);
HandleFromUriObjectParams(operation, schemaRegistry, apiDescription);
}
开发者ID:ConstYavorskiy,项目名称:Swashbuckle,代码行数:7,代码来源:HandleFromUriParams.cs
示例9: WriteParameters
/// <summary>Writes the parameters.</summary>
/// <param name="apiDescription">The API description.</param>
public void WriteParameters(ApiDescription apiDescription)
{
Condition.Requires(apiDescription).IsNotNull();
if (apiDescription.ParameterDescriptions.Any())
{
Writer.WriteLine("**Parameters** ");
}
foreach (var pd in apiDescription.ParameterDescriptions)
{
if (pd.ParameterDescriptor != null)
{
Writer.Write("`{0}` {1} - ", pd.ParameterDescriptor.ParameterType.GetFriendlyTypeName(), pd.Name);
if (!string.IsNullOrEmpty(pd.Documentation))
{
Writer.Write("_{0}_, ", pd.Documentation);
}
if (pd.ParameterDescriptor.DefaultValue != null)
{
Writer.Write("default [{0}], ", pd.ParameterDescriptor.DefaultValue);
}
Writer.WriteLine("{0} ", pd.ParameterDescriptor.IsOptional ? "optional" : "required");
}
};
}
开发者ID:jamesholcomb,项目名称:Postman.WebApi.MsBuildTask,代码行数:31,代码来源:DocumentationWriter.cs
示例10: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null)
{
throw new ArgumentNullException("operation");
}
if (apiDescription == null)
{
throw new ArgumentNullException("apiDescription");
}
Collection<IFilter> filters = apiDescription.ActionDescriptor.ControllerDescriptor.GetFilters();
IEnumerable<IFilter> mobileAppFilter = filters.Where(f => typeof(MobileAppControllerAttribute).IsAssignableFrom(f.GetType()));
if (mobileAppFilter.Any())
{
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
operation.parameters.Add(new Parameter
{
name = "ZUMO-API-VERSION",
@in = "header",
type = "string",
required = true,
@default = "2.0.0"
});
}
}
开发者ID:Azure,项目名称:azure-mobile-apps-net-server,代码行数:32,代码来源:MobileAppHeaderFilter.cs
示例11: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
List<SwaggerDefaultValue> listDefine = new List<SwaggerDefaultValue>
{
new SwaggerDefaultValue("Compare", "<", "<,<=,>,>=,="),
//new SwaggerDefaultValue("Model_URI", "@{body(\'besconnector').Results.output2.FullURL}"),
//new SwaggerDefaultValue("Evaluate_Output_Path", "@{body(\'besconnector\').Results.output1.FullURL}")
};
if (operation.parameters == null)
return;
foreach (var param in operation.parameters)
{
var actionParam = apiDescription.ActionDescriptor.GetParameters().First(p => p.ParameterName == param.name);
foreach (SwaggerDefaultValue customAttribute in listDefine)
{
if (customAttribute.ParameterName == param.name)
{
[email protected] = customAttribute.DefaultValue;
string[] listValue = customAttribute.Values.Split(',');
if (listValue != null && listValue.Length > 1)
[email protected] = listValue;
}
}
}
}
开发者ID:raymondlaghaeian,项目名称:LogicApp-BES,代码行数:27,代码来源:SwaggerConfig.cs
示例12: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
// Determine if the operation has the Authorize attribute
var authorizeAttributes = apiDescription
.ActionDescriptor.GetCustomAttributes<AuthorizeAttribute>();
if (!authorizeAttributes.Any())
return;
// Correspond each "Authorize" role to an oauth2 scope
var scopes =
authorizeAttributes
.SelectMany(attr => attr.Roles.Split(','))
.Distinct()
.ToList();
// Initialize the operation.security property if it hasn't already been
if (operation.security == null)
operation.security = new List<IDictionary<string, IEnumerable<string>>>();
var oAuthRequirements = new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", scopes }
};
operation.security.Add(oAuthRequirements);
}
开发者ID:huoxudong125,项目名称:SwaggerDemoApi,代码行数:27,代码来源:SwaggerConfig.cs
示例13: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var hasAuthorizeAttr = apiDescription.ActionDescriptor.GetFilterPipeline()
.Select(filterInfo => filterInfo.Instance)
.Any(filter => filter is IAuthorizationFilter);
var hasAllowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any();
if (hasAuthorizeAttr && !hasAllowAnonymous)
{
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
operation.parameters.Add(new Parameter()
{
description = "Authorization token. Used for applying content access restrictions. Use one of the OAuth2 grants to auto-populate this value.",
@in = "header",
name = "Authorization",
required = true,
type = "string",
@default = "bearer "
});
}
}
开发者ID:Fanuer,项目名称:EventCorp,代码行数:26,代码来源:AddParametersFilter.cs
示例14: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null)
{
throw new ArgumentNullException("operation");
}
if (apiDescription == null)
{
throw new ArgumentNullException("apiDescription");
}
// Correspond each "Authorize" action to an oauth2 scope
var authorized = apiDescription.ActionDescriptor.GetFilterPipeline()
.Select(filterInfo => filterInfo.Instance)
.OfType<AuthorizeAttribute>()
.Distinct();
if (authorized.Any())
{
if (operation.security == null)
{
operation.security = new List<IDictionary<string, IEnumerable<string>>>();
}
var requirements = new Dictionary<string, IEnumerable<string>>
{
{ this.provider, new string[] { } }
};
operation.security.Add(requirements);
}
}
开发者ID:Azure,项目名称:azure-mobile-apps-net-server,代码行数:33,代码来源:MobileAppAuthenticationFilter.cs
示例15: HeaderFilter_AddsHeaderRequirement
public void HeaderFilter_AddsHeaderRequirement(Collection<IFilter> filters)
{
// Arrange
var swashbuckleFilter = new MobileAppHeaderFilter();
var operation = new Operation();
var controllerDescMock = new Mock<HttpControllerDescriptor>();
controllerDescMock.Setup(c => c.GetFilters()).Returns(filters);
var description = new ApiDescription();
description.ActionDescriptor = new ReflectedHttpActionDescriptor();
description.ActionDescriptor.ControllerDescriptor = controllerDescMock.Object;
// Act
swashbuckleFilter.Apply(operation, null, description);
// Assert
Assert.NotNull(operation.parameters);
Assert.Equal(1, operation.parameters.Count);
Parameter parameter = operation.parameters[0];
Assert.Equal("ZUMO-API-VERSION", parameter.name);
Assert.Equal("header", [email protected]);
Assert.Equal("string", parameter.type);
Assert.Equal("2.0.0", [email protected]);
Assert.True(parameter.required);
}
开发者ID:Azure,项目名称:azure-mobile-apps-net-server,代码行数:26,代码来源:MobileAppHeaderFilterTests.cs
示例16: Apply
public void Apply(
ApiDescription apiDescription,
OperationSpec operationSpec,
ModelSpecRegistrar modelSpecRegistrar,
ModelSpecGenerator modelSpecGenerator)
{
var responseTypeAttr = apiDescription.ActionDescriptor.GetCustomAttributes<ResponseTypeAttribute>().FirstOrDefault();
if (responseTypeAttr == null) return;
IEnumerable<ModelSpec> complexSpecs;
var modelSpec = modelSpecGenerator.TypeToModelSpec(responseTypeAttr.Type, out complexSpecs);
if (modelSpec.Type == "object")
{
operationSpec.Type = modelSpec.Id;
}
else
{
operationSpec.Type = modelSpec.Type;
operationSpec.Format = modelSpec.Format;
operationSpec.Items = modelSpec.Items;
operationSpec.Enum = modelSpec.Enum;
}
modelSpecRegistrar.RegisterMany(complexSpecs);
}
开发者ID:jfurie,项目名称:Swashbuckle,代码行数:25,代码来源:ApplyCustomResponseTypes.cs
示例17: MobileAppAuthFilter_AddsSecurity_WhenAuthorizeSpecified
public void MobileAppAuthFilter_AddsSecurity_WhenAuthorizeSpecified()
{
// Arrange
var filter = new MobileAppAuthenticationFilter("facebook");
var operation = new Operation();
var apiDescription = new ApiDescription();
var actionDescMock = new Mock<HttpActionDescriptor>();
Collection<FilterInfo> pipeline = new Collection<FilterInfo>()
{
new FilterInfo(new AuthorizeAttribute(), FilterScope.Action)
};
actionDescMock.Setup(a => a.GetFilterPipeline()).Returns(pipeline);
apiDescription.ActionDescriptor = actionDescMock.Object;
// Act
filter.Apply(operation, null, apiDescription);
// Assert
Assert.NotNull(operation.security);
Assert.Equal(1, operation.security.Count);
Assert.Equal(1, operation.security[0].Keys.Count);
Assert.Equal("facebook", operation.security[0].Keys.First());
Assert.Equal(0, operation.security[0]["facebook"].Count());
}
开发者ID:Azure,项目名称:azure-mobile-apps-net-server,代码行数:25,代码来源:MobileAppAuthenticationFilterTests.cs
示例18: Apply
public void Apply(Operation operation, DataTypeRegistry dataTypeRegistry, ApiDescription apiDescription)
{
var methodNode = _navigator.SelectSingleNode(GetXPathFor(apiDescription.ActionDescriptor));
operation.Summary = GetChildValueOrDefault(methodNode, SummaryExpression);
operation.Notes = GetChildValueOrDefault(methodNode, RemarksExpression);
foreach (var paramDesc in apiDescription.ParameterDescriptions)
{
if (paramDesc.ParameterDescriptor == null) continue; // not in action signature (e.g. route parameter)
var parameter = operation.Parameters.SingleOrDefault(p => p.Name == paramDesc.Name);
if (parameter == null) continue;
parameter.Description = GetChildValueOrDefault(
methodNode,
String.Format(ParameterExpression, paramDesc.ParameterDescriptor.ParameterName));
}
if (methodNode == null) return;
foreach (var responseMessage in GetResponseMessages(methodNode))
{
operation.ResponseMessages.Add(responseMessage);
}
}
开发者ID:AnthonyNeace,项目名称:Swashbuckle,代码行数:26,代码来源:ApplyActionXmlComments.cs
示例19: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.operationId != "Products_GetAllByType") return;
var response = operation.responses["200"];
response.vendorExtensions = new Dictionary<string, object>();
response.vendorExtensions.Add("x-foo", "bar");
}
开发者ID:RobStand,项目名称:Swashbuckle,代码行数:8,代码来源:ApplyResponseVendorExtensions.cs
示例20: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var descriptor = apiDescription.ActionDescriptor as ControllerlessActionDescriptor;
operation.summary = descriptor != null
? this.provider.GetDescription(descriptor.MessageType)
: operation.summary;
}
开发者ID:dotnetjunkie,项目名称:solidservices,代码行数:8,代码来源:SwaggerConfig.cs
注:本文中的System.Web.Http.Description.ApiDescription类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论