private static List ConvertStringToJObjectList()

in Forge.TreeWalker/src/ForgeSchemaValidator.cs [130:164]


        private static List<JObject> ConvertStringToJObjectList(string schema, bool validateAsDictionary)
        {
            List<JObject> schemaList = new List<JObject>();

            // There could be three possible cases:
            // 1. schema is a Dictionary<string, ForgeTree> and should be validated as a dictionary.
            // 2. schema is a Dictionary<string, ForgeTree> and should be validated as individual ForgeTree's.
            // 3. schema is a ForgeTree and should be validated as a single ForgeTree.
            Dictionary<string, ForgeTree> forgeTrees = JsonConvert.DeserializeObject<Dictionary<string, ForgeTree>>(schema);

            if (validateAsDictionary)
            {
                schemaList.Add(JObject.Parse(schema));
            }
            else
            {
                foreach (KeyValuePair<string, ForgeTree> kvp in forgeTrees)
                {
                    ForgeTree forgeTree = kvp.Value;

                    if (forgeTree.Tree == null)
                    {
                        // Deserialize into Dictionary does not throw exception but will have null "Tree" property if schema is just a ForgeTree.
                        // Try to deserialize string into ForgeTree directly.
                        JsonConvert.DeserializeObject<ForgeTree>(schema);
                        schemaList.Add(JObject.Parse(schema));
                        break;
                    }

                    schemaList.Add(SerializeToJObject(forgeTree));
                }
            }

            return schemaList;
        }