本文整理汇总了C#中System.Web.Http.Description.ApiParameterDescription类的典型用法代码示例。如果您正苦于以下问题:C# ApiParameterDescription类的具体用法?C# ApiParameterDescription怎么用?C# ApiParameterDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiParameterDescription类属于System.Web.Http.Description命名空间,在下文中一共展示了ApiParameterDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateParameter
public ApiParameter CreateParameter(ApiParameterDescription parameterDescription, string relativePath)
{
var trueParamType = parameterDescription.ParameterDescriptor.ParameterType;
var paramType = GetParamType(parameterDescription, relativePath);
var isRequired = !parameterDescription.ParameterDescriptor.IsOptional;
var dataType = GetFriendlyTypeName(trueParamType);
var allowMuliple = GetAllowMuliple(trueParamType);
if (parameterDescription.ParameterDescriptor.ParameterType.IsEnum)
{
var possibleValues = new AllowableValues(trueParamType);
return new ApiEnumParameter()
{
name = parameterDescription.Name,
dataType = dataType,
paramType = paramType.ToString(),
description = parameterDescription.Documentation,
allowMultiple = allowMuliple,
required = isRequired,
allowableValues = possibleValues
};
}
return new ApiParameter()
{
name = parameterDescription.Name,
dataType = dataType,
paramType = paramType.ToString(),
description = parameterDescription.Documentation,
allowMultiple = allowMuliple,
required = isRequired
};
}
示例2: GetParamType
private static ParamType GetParamType(ApiParameterDescription parameterDescription, string relativePath)
{
var paramType = ParamType.body;
if (parameterDescription.Source == ApiParameterSource.FromUri)
{
paramType = relativePath.IndexOf("{" + parameterDescription.Name + "}") > -1 ? ParamType.path : ParamType.query;
}
return paramType;
}
示例3: CreateParameter
public static ApiParameterDescription CreateParameter(string name, Type type, bool isOptional, ApiParameterSource source)
{
var p = MockRepository.GenerateStub<HttpParameterDescriptor>();
p.Stub(x => x.ParameterName).Return(name);
p.Stub(x => x.ParameterType).Return(type);
p.Stub(x => x.IsOptional).Return(isOptional);
var apiParam = new ApiParameterDescription() { ParameterDescriptor = p, Name = name, Source = source, Documentation = "yada" };
return apiParam;
}
示例4: CreateParameter
/// <summary>
/// Creates an operation parameter
/// </summary>
/// <param name="param">Description of a parameter on an operation via the ApiExplorer</param>
/// <returns>An operation parameter</returns>
public Parameter CreateParameter(ApiParameterDescription param)
{
var returnType = param.ParameterDescriptor.ParameterType.GetSwaggerType();
return new Parameter()
{
ParamTypeEnum = param.GetParamType(),
Name = param.Name,
Description = param.Documentation,
Type = returnType.Type,
Format = returnType.Format,
Enum = returnType.Enum,
Required = !param.ParameterDescriptor.IsOptional,
Items = param.ParameterDescriptor.ParameterType.IsIEnumerable() ? new Items{ Type = "string" } : null
};
}
示例5: GetBindableProperties_WorksOnlyFor_PublicInstanceProperties_WithPublicGettersAndSetters
public void GetBindableProperties_WorksOnlyFor_PublicInstanceProperties_WithPublicGettersAndSetters()
{
// Arrange
ApiParameterDescription parameter = new ApiParameterDescription();
Mock<HttpParameterDescriptor> parameterDescriptorMock = new Mock<HttpParameterDescriptor>();
parameterDescriptorMock.SetupGet(p => p.ParameterType).Returns(typeof(ClassWithAllKindsOfProperties));
parameter.ParameterDescriptor = parameterDescriptorMock.Object;
// Act
IEnumerable<PropertyInfo> bindableProperties = parameter.GetBindableProperties();
// Assert
Assert.Equal(1, bindableProperties.Count());
Assert.Equal("ValidProperty", bindableProperties.Single().Name);
}
示例6: CreateParameter
private Parameter CreateParameter(ApiParameterDescription apiParamDesc, string apiPath)
{
var paramType = "";
switch (apiParamDesc.Source)
{
case ApiParameterSource.FromBody:
paramType = "body";
break;
case ApiParameterSource.FromUri:
paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query";
break;
}
if (apiParamDesc.ParameterDescriptor == null)
{
return new Parameter { ParamType = paramType, Name = apiParamDesc.Name, Required = true, Type = "string" };
}
var parameter = new Parameter
{
ParamType = paramType,
Name = apiParamDesc.Name,
Description = apiParamDesc.Documentation,
Required = !apiParamDesc.ParameterDescriptor.IsOptional
};
var dataType = _dataTypeRegistry.GetOrRegister(apiParamDesc.ParameterDescriptor.ParameterType);
if (dataType.Type == "object")
{
parameter.Type = dataType.Id;
}
else
{
parameter.Type = dataType.Type;
parameter.Format = dataType.Format;
parameter.Items = dataType.Items;
parameter.Enum = dataType.Enum;
}
return parameter;
}
示例7: CreateParameter
private Parameter CreateParameter(ApiParameterDescription apiParamDesc, string apiPath, Dictionary<string, DataType> complexModels)
{
var paramType = "";
switch (apiParamDesc.Source)
{
case ApiParameterSource.FromBody:
paramType = "body";
break;
case ApiParameterSource.FromUri:
paramType = apiPath.Contains(String.Format("{{{0}}}", apiParamDesc.Name)) ? "path" : "query";
break;
}
var parameter = new Parameter
{
ParamType = paramType,
Name = apiParamDesc.Name,
Description = apiParamDesc.Documentation,
Required = !apiParamDesc.ParameterDescriptor.IsOptional
};
IDictionary<string, DataType> complexModelsForParameter;
var dataType = _dataTypeGenerator.TypeToDataType(apiParamDesc.ParameterDescriptor.ParameterType, out complexModelsForParameter);
complexModels.Merge(complexModelsForParameter);
if (dataType.Type == "object")
{
parameter.Type = dataType.Id;
}
else
{
parameter.Type = dataType.Type;
parameter.Format = dataType.Format;
parameter.Items = dataType.Items;
parameter.Enum = dataType.Enum;
}
return parameter;
}
示例8: BuildArguments
private static string BuildArguments(ApiParameterDescription[] parameters)
{
if(parameters == null || parameters.Length == 0)
{
return string.Empty;
}
StringBuilder sb = new StringBuilder();
int i = 0;
foreach(var p in parameters)
{
sb.Append(p.Name);
if(i!= parameters.Length-1)
{
sb.Append(",");
}
i += 1;
}
return sb.ToString();
}
示例9: CreateParameterSpec
private ParameterSpec CreateParameterSpec(ApiParameterDescription apiParamDesc, string apiPath, ModelSpecRegistrar modelSpecRegistrar)
{
var paramType = "";
switch (apiParamDesc.Source)
{
case ApiParameterSource.FromBody:
paramType = "body";
break;
case ApiParameterSource.FromUri:
paramType = apiPath.Contains(apiParamDesc.Name) ? "path" : "query";
break;
}
var paramSpec = new ParameterSpec
{
ParamType = paramType,
Name = apiParamDesc.Name,
Description = apiParamDesc.Documentation,
Required = !apiParamDesc.ParameterDescriptor.IsOptional
};
var modelSpec = _modelSpecGenerator.From(apiParamDesc.ParameterDescriptor.ParameterType, modelSpecRegistrar);
if (modelSpec.Type == "object")
{
paramSpec.Type = modelSpec.Id;
}
else
{
paramSpec.Type = modelSpec.Type;
paramSpec.Format = modelSpec.Format;
paramSpec.Items = modelSpec.Items;
paramSpec.Enum = modelSpec.Enum;
}
return paramSpec;
}
示例10: CreateResourceApiOperationParameter
/// <summary>
/// Creates an operation parameter
/// </summary>
/// <param name="api">Description of the api via the ApiExplorer</param>
/// <param name="param">Description of a parameter on an operation via the ApiExplorer</param>
/// <param name="docProvider">Access to the XML docs written in code</param>
/// <returns>An operation parameter</returns>
public static ResourceApiOperationParameter CreateResourceApiOperationParameter(ApiDescription api, ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
{
string paramType = (param.Source.ToString().Equals(FROMURI)) ? QUERY : BODY;
ResourceApiOperationParameter parameter = new ResourceApiOperationParameter()
{
paramType = (paramType == "query" && api.RelativePath.IndexOf("{" + param.Name + "}") > -1) ? PATH : paramType,
name = param.Name,
description = param.Documentation,
dataType = param.ParameterDescriptor.ParameterType.Name,
required = docProvider.GetRequired(param.ParameterDescriptor)
};
return parameter;
}
示例11: AddParameterDescription
public static ParameterDescription AddParameterDescription(
this Collection<ParameterDescription> uriParameters,
ApiParameterDescription apiParameter, ModelDescription typeDescription)
{
var parameterDescription = new ParameterDescription
{
Name = apiParameter.Name,
Documentation = apiParameter.Documentation,
TypeDescription = typeDescription,
};
uriParameters.Add(parameterDescription);
return parameterDescription;
}
示例12: GetParameterLocation
private string GetParameterLocation(ApiDescription apiDesc, ApiParameterDescription paramDesc)
{
if (apiDesc.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}"))
return "path";
else if (paramDesc.Source == ApiParameterSource.FromBody && apiDesc.HttpMethod != HttpMethod.Get)
return "body";
else
return "query";
}
示例13: GenerateParameterSpec
private ParameterSpec GenerateParameterSpec(ApiParameterDescription parameterDescription, string apiPath, ModelSpecMap modelSpecMap)
{
var paramType = "";
switch (parameterDescription.Source)
{
case ApiParameterSource.FromBody:
paramType = "body";
break;
case ApiParameterSource.FromUri:
paramType = apiPath.Contains(parameterDescription.Name) ? "path" : "query";
break;
}
var paramSpec = new ParameterSpec
{
ParamType = paramType,
Name = parameterDescription.Name,
Description = parameterDescription.Documentation,
Required = !parameterDescription.ParameterDescriptor.IsOptional
};
var modelSpec = modelSpecMap.FindOrCreateFor(parameterDescription.ParameterDescriptor.ParameterType);
if (modelSpec.Type == "object")
{
paramSpec.Type = modelSpec.Id;
}
else
{
paramSpec.Type = modelSpec.Type;
paramSpec.Format = modelSpec.Format;
paramSpec.Items = modelSpec.Items;
paramSpec.Enum = modelSpec.Enum;
}
return paramSpec;
}
示例14: CreateResourceModel
public static IList<ResourceModelNode> CreateResourceModel(ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
{
return CreateResourceModel(param, param.ParameterDescriptor.ParameterType, docProvider);
}
示例15: CreateParameter
private Parameter CreateParameter(string location, ApiParameterDescription paramDesc, SchemaRegistry schemaRegistry)
{
var parameter = new Parameter
{
@in = location,
name = paramDesc.Name
};
if (paramDesc.ParameterDescriptor == null)
{
parameter.type = "string";
parameter.required = true;
return parameter;
}
parameter.required = location == "path" || !paramDesc.ParameterDescriptor.IsOptional;
[email protected] = paramDesc.ParameterDescriptor.DefaultValue;
var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType);
if ([email protected] == "body")
parameter.schema = schema;
else
parameter.PopulateFrom(schema);
return parameter;
}