Ejemplo n.º 1
0
        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
                          };
        }
Ejemplo n.º 2
0
        public object CreateModel(Type type)
        {
            var properties = new Dictionary<string, object>();


            if (type.IsEnum)
            {
                var allowableVals = new AllowableValues(type);
                var itemDocs = _docProvider.GetDocumentation(type);
                var item = new { allowableValues = allowableVals, description = itemDocs, type = "string" };
                properties["PossibleValues"] = item;
            }
            else
            {
                foreach (var prop in type.GetProperties())
                {
                    properties[prop.Name] = GetProperty(prop);
                }
            }

            return new ApiModel
            {
                id = type.Name,
                properties = properties,
                description = _docProvider.GetDocumentation(type)
            };
        }
Ejemplo n.º 3
0
        private object GetProperty(PropertyInfo prop)
        {

            object item;
            var docs = _docProvider.GetDocumentation(prop);
            if (prop.PropertyType.IsArray)
            {   // Array
                item = new
                {
                    type = prop.PropertyType.GetElementType().Name + "[]",
                    items = new { Sref = prop.PropertyType.GetElementType().Name },
                    description = docs
                };
            }
            else if (prop.PropertyType.IsPrimitive)
            {   // Primative
                item = new
                {
                    type = prop.PropertyType.Name,
                    description = docs
                };
            }
            else if (prop.PropertyType.IsEnum)
            {
                //"status": {
                //  "allowableValues": {
                //      "valueType": "LIST",
                //      "values": [
                //   "available",
                //   "pending",
                //   "sold"
                //],
                //      "valueType": "LIST"
                //  },
                //  "description": "pet status in the store",
                //  "type": "string"
                //}
                // Enum
                var allowableVals = new AllowableValues(prop.PropertyType);
                item = new { allowableValues = allowableVals, description = docs, type = "string" };
            }

            //else if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof (Nullable<>))
            else if (prop.PropertyType.IsGenericType)
            {
                var gType = prop.PropertyType.GetGenericArguments().First();
                var name = Utils.GetCleanTypeName(gType);
                name = name.Substring(name.IndexOf(".") + 1);
                item = new { type = name + "?", description = docs };
            }
            else
            {

                item = new { type = prop.PropertyType.Name, description = docs };

            }

            return item;
        }