private static FilePath SplitAndWriteJson(JsonNode parsed, FilePath dir, string name) { var f = new JsonFormatter(4); Traverse(parsed, f, dir); var json = f.ToString(); var path = dir.Child(string.Format("{0}.schema.json", name)); Debug.LogFormat("write JsonSchema: {0}", path.FullPath); File.WriteAllText(path.FullPath, json); return(path); }
private static void TraverseItem(JsonNode node, JsonFormatter f, FilePath dir) { var title = GetTitle(node); if (string.IsNullOrEmpty(title)) { Traverse(node, f, dir); } else { // ref f.BeginMap(); f.Key("$ref"); var fileName = string.Format("{0}.schema.json", title); f.Value(fileName); f.EndMap(); // new formatter { var subFormatter = new JsonFormatter(4); subFormatter.BeginMap(); foreach (var _kv in node.ObjectItems()) { subFormatter.Key(_kv.Key.GetUtf8String()); Traverse(_kv.Value, subFormatter, dir); } subFormatter.EndMap(); var subJson = subFormatter.ToString(); var path = dir.Child(fileName); File.WriteAllText(path.FullPath, subJson); } } }