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) }); }
public static RamlType GetRamlType(KeyValuePair <string, object> type) { var key = type.Key; var required = true; if (key.EndsWith("?")) { key = key.Substring(0, key.Length - 1); required = false; } var ramlType = new RamlType(); ramlType.Name = key; ramlType.Required = required; var simpleProperty = type.Value as string; if (simpleProperty != null) { if (simpleProperty.StartsWith("<")) { ramlType.External = new ExternalType { Xml = simpleProperty }; return(ramlType); } if (simpleProperty.StartsWith("{")) { ramlType.External = new ExternalType { Schema = simpleProperty }; return(ramlType); } ramlType.Scalar = GetScalar(type, required); return(ramlType); } var dynamicRaml = type.Value as IDictionary <string, object>; if (dynamicRaml == null) { throw new InvalidOperationException("Cannot parse type: " + type.Key); } var value = (IDictionary <string, object>)type.Value; ramlType = new RamlType { Name = type.Key, Type = GetType(value), Example = DynamicRamlParser.GetExample(value), Facets = DynamicRamlParser.GetDictionaryOrNull <object>(value, "facets"), OtherProperties = GetOtherProperties(value), Required = GetRequired(value, required) }; SetPropertiesByType(type, ramlType); return(ramlType); }