Ejemplo n.º 1
0
        private static Dictionary <string, Resource> GetFields(dynamic resources)
        {
            Dictionary <string, Resource> allRequired = new Dictionary <string, Resource>();

            foreach (dynamic resource in resources)
            {
                if (!Resources.ShowItem(resource) || resource.name.Value == "metadata" || resource.name.Value == "meta_table_description")
                {
                    continue;
                }
                Resource requiredResource = new Resource(resource.name.Value);
                foreach (dynamic field in resource.schema.fields)
                {
                    if (!Resources.ShowItem(field) || field.name.Value.EndsWith("_id"))
                    {
                        continue;
                    }
                    bool isRequired = false;
                    bool isUnique   = false;
                    if (field.constraints != null && field.constraints.required != null && field.constraints.required.Value)
                    {
                        isRequired = true;
                    }
                    if (field.constraints != null && field.constraints.unique != null && field.constraints.unique.Value)
                    {
                        isUnique = true;
                    }
                    HashSet <string> enums = new HashSet <string>();
                    if (field.constraints != null && field.constraints.@enum != null)
                    {
                        foreach (string enumVal in field.constraints.@enum)
                        {
                            enums.Add(enumVal);
                        }
                    }
                    string format = string.Empty;
                    if (field.format != null)
                    {
                        format = field.format.Value;
                    }
                    string dataType = string.Empty;
                    if (field.type != null)
                    {
                        dataType = field.type.Value;
                    }
                    requiredResource.AddField(new Field(field.name.Value, format, dataType, isRequired, isUnique, enums));
                }
                allRequired.Add(resource.name.Value, requiredResource);
            }
            return(allRequired);
        }