当前位置: 首页>>代码示例>>C#>>正文


C# Description.ApiParameterDescription类代码示例

本文整理汇总了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
                          };
        }
开发者ID:antonsamarsky,项目名称:Swagger.Net,代码行数:34,代码来源:ParameterFactory.cs

示例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;
 }
开发者ID:antonsamarsky,项目名称:Swagger.Net,代码行数:9,代码来源:ParameterFactory.cs

示例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;
        }
开发者ID:danieleli,项目名称:Swagger.Net,代码行数:10,代码来源:TestHelper.cs

示例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 
     };
 }
开发者ID:Tom-Kennedy,项目名称:Swagger.Net,代码行数:20,代码来源:SwaggerGen.cs

示例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);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:15,代码来源:ApiParameterDescriptionTest.cs

示例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;
        }
开发者ID:AnthonyNeace,项目名称:Swashbuckle,代码行数:42,代码来源:OperationGenerator.cs

示例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;
        }
开发者ID:kevynb,项目名称:Swashbuckle,代码行数:40,代码来源:OperationGenerator.cs

示例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();
        }
开发者ID:BinRelease,项目名称:SlashGetNet,代码行数:22,代码来源:AngularScriptManager.cs

示例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;
        }
开发者ID:robinvanderknaap,项目名称:Swashbuckle.Lite,代码行数:37,代码来源:OperationSpecGenerator.cs

示例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;
        }
开发者ID:DveMac,项目名称:Swagger.Net,代码行数:21,代码来源:SwaggerModels.cs

示例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;
        }
开发者ID:ouyh18,项目名称:LtePlatform,代码行数:14,代码来源:HelpPageConfigurationExtensions.cs

示例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";
 }
开发者ID:sk8tz,项目名称:Swashbuckle,代码行数:9,代码来源:SwaggerGenerator.cs

示例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;
        }
开发者ID:nprovencher,项目名称:Swashbuckle,代码行数:36,代码来源:SwaggerGenerator.cs

示例14: CreateResourceModel

 public static IList<ResourceModelNode> CreateResourceModel(ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
 {
     return CreateResourceModel(param, param.ParameterDescriptor.ParameterType, docProvider);
 }
开发者ID:giacomelli,项目名称:DG-Swagger.Net,代码行数:4,代码来源:SwaggerModels.cs

示例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;
        }
开发者ID:sk8tz,项目名称:Swashbuckle,代码行数:26,代码来源:SwaggerGenerator.cs


注:本文中的System.Web.Http.Description.ApiParameterDescription类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。