예제 #1
0
        void Traverse(JsonSchemaSource source, string rootName = default)
        {
            foreach (var child in source.Children())
            {
                Traverse(child);
            }

            switch (source.type)
            {
            case JsonSchemaType.Object:
            {
                var schema = source.Create(true);
                if (schema is ObjectJsonSchema obj)
                {
                    if (!string.IsNullOrEmpty(rootName))
                    {
                        obj.Title = rootName;
                    }
                    WriteObject(obj, rootName);
                }
                else if (schema is ExtensionJsonSchema ext)
                {
                    // WriteObject(ext);
                }
                else if (schema is DictionaryJsonSchema dict)
                {
                    WriteObject((ObjectJsonSchema)dict.AdditionalProperties, rootName);
                }
                else
                {
                    throw new Exception();
                }
            }
            break;

            case JsonSchemaType.EnumString:
                WriteEnumString(source.Create(true) as EnumStringJsonSchema);
                break;
            }
        }
 public static void Write(TextWriter w, JsonSchemaSource root, string rootName)
 {
     w.Write(Begin.Replace("$0", rootName));
     root.Create(true, rootName).GenerateSerializer(new TraverseContext(w), "Serialize");
     w.Write(End);
 }