Пример #1
0
        public Property Build(IDictionary <string, object> dynamicRaml)
        {
            var prop = new Property();

            ParameterBuilder.SetProperties(dynamicRaml, prop);
            prop.Facets     = TypeExtractor.GetType(dynamicRaml, "string");
            prop.Format     = GetFormat(dynamicRaml);
            prop.MultipleOf = dynamicRaml.ContainsKey("multipleOf") ? Convert.ToInt32(dynamicRaml["multipleOf"]) : (int?)null;
            prop.FileTypes  = GetFileTypes(dynamicRaml).ToList();
            return(prop);
        }
Пример #2
0
        public MimeType GetMimeType(object mimeType)
        {
            var value = mimeType as IDictionary <string, object>;

            if (value == null)
            {
                var schema = mimeType as string;
                return(!string.IsNullOrWhiteSpace(schema) ? new MimeType {
                    Schema = schema
                } : null);
            }

            if (value.ContainsKey("body") && value["body"] is IDictionary <string, object> )
            {
                value = (IDictionary <string, object>)value["body"];
            }

            RamlType ramlType = null;

            if (value.ContainsKey("type") && value.ContainsKey("properties"))
            {
                ramlType = TypeBuilder.GetRamlType(new KeyValuePair <string, object>("obj", mimeType));
            }

            if (value.ContainsKey("application/json"))
            {
                value = value["application/json"] as IDictionary <string, object>;
            }

            if (value.ContainsKey("type") && (value["type"] as IDictionary <string, object>) != null &&
                ((IDictionary <string, object>)value["type"]).ContainsKey("properties"))
            {
                ramlType = TypeBuilder.GetRamlType(new KeyValuePair <string, object>("obj", value["type"]));
            }

            return(new MimeType
            {
                Type = TypeExtractor.GetType(value),
                InlineType = ramlType,
                Description = value.ContainsKey("description") ? (string)value["description"] : null,
                Example = DynamicRamlParser.GetExample(value),
                Schema = GetSchema(value),
                FormParameters = value.ContainsKey("formParameters")
                                               ? GetParameters((IDictionary <string, object>)value["formParameters"])
                                               : null,
                Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml)
            });
        }
Пример #3
0
        public ResourceType Build(IDictionary <string, object> dynamicRaml, string defaultMediaType)
        {
            var resourceType = new ResourceType
            {
                Type        = TypeExtractor.Get(dynamicRaml),
                Is          = TypeExtractor.GetIs(dynamicRaml),
                Get         = GetVerb(dynamicRaml, "get", VerbType.GET, defaultMediaType),
                Post        = GetVerb(dynamicRaml, "post", VerbType.POST, defaultMediaType),
                Put         = GetVerb(dynamicRaml, "put", VerbType.PUT, defaultMediaType),
                Delete      = GetVerb(dynamicRaml, "delete", VerbType.DELETE, defaultMediaType),
                Patch       = GetVerb(dynamicRaml, "patch", VerbType.PATCH, defaultMediaType),
                Options     = GetVerb(dynamicRaml, "options", VerbType.OPTIONS, defaultMediaType),
                Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml)
            };

            return(resourceType);
        }
 public static void SetProperties(IDictionary <string, object> dynamicRaml, Parameter parameter)
 {
     parameter.Type        = TypeExtractor.GetType(dynamicRaml);
     parameter.Required    = dynamicRaml.ContainsKey("required") && Convert.ToBoolean(dynamicRaml["required"]);
     parameter.DisplayName = dynamicRaml.ContainsKey("displayName") ? (string)dynamicRaml["displayName"] : null;
     parameter.Description = dynamicRaml.ContainsKey("description") ? (string)dynamicRaml["description"] : null;
     parameter.Enum        = GetEnum(dynamicRaml);
     parameter.Repeat      = dynamicRaml.ContainsKey("repeat") && Convert.ToBoolean(dynamicRaml["repeat"]);
     parameter.Example     = dynamicRaml.ContainsKey("example") ? dynamicRaml["example"].ToString() : null;
     parameter.Default     = dynamicRaml.ContainsKey("default")
             ? (dynamicRaml["default"] != null ? dynamicRaml["default"].ToString() : null)
             : null;
     parameter.Pattern     = dynamicRaml.ContainsKey("pattern") ? (string)dynamicRaml["pattern"] : null;
     parameter.MinLength   = dynamicRaml.ContainsKey("minLength") ? Convert.ToInt32(dynamicRaml["minLength"]) : (int?)null;
     parameter.MaxLength   = dynamicRaml.ContainsKey("maxLength") ? Convert.ToInt32(dynamicRaml["maxLength"]) : (int?)null;
     parameter.Minimum     = dynamicRaml.ContainsKey("minimum") ? Convert.ToDecimal(dynamicRaml["minimum"]) : (decimal?)null;
     parameter.Maximum     = dynamicRaml.ContainsKey("maximum") ? Convert.ToDecimal(dynamicRaml["maximum"]) : (decimal?)null;
     parameter.Annotations = AnnotationsBuilder.GetAnnotations(dynamicRaml);
 }
Пример #5
0
        private static string GetType(IDictionary <string, object> typeValue)
        {
            var extractedType = TypeExtractor.GetType(typeValue, "object");

            if (preffix == null)
            {
                return(extractedType);
            }
            if (PrimitiveTypes.Contains(extractedType))
            {
                return(extractedType);
            }

            if (extractedType == "object" || extractedType == "array")
            {
                return(extractedType);
            }

            return(preffix + "." + extractedType);
        }