public JsonSchemaNode AddSchema(JsonSchemaNode existingNode, JsonSchema schema)
        {
            string newId;

            if (existingNode != null)
            {
                if (existingNode.Schemas.Contains(schema))
                {
                    return(existingNode);
                }

                newId = JsonSchemaNode.GetId(existingNode.Schemas.Union(new[] { schema }));
            }
            else
            {
                newId = JsonSchemaNode.GetId(new[] { schema });
            }

            if (_nodes.Contains(newId))
            {
                return(_nodes[newId]);
            }

            JsonSchemaNode currentNode =
                (existingNode != null) ? existingNode.Combine(schema) : new JsonSchemaNode(schema);

            _nodes.Add(currentNode);

            AddProperties(schema.Properties, currentNode.Properties);

            AddProperties(schema.PatternProperties, currentNode.PatternProperties);

            if (schema.Items != null)
            {
                for (int i = 0; i < schema.Items.Count; i++)
                {
                    AddItem(currentNode, i, schema.Items[i]);
                }
            }

            if (schema.AdditionalItems != null)
            {
                AddAdditionalItems(currentNode, schema.AdditionalItems);
            }

            if (schema.AdditionalProperties != null)
            {
                AddAdditionalProperties(currentNode, schema.AdditionalProperties);
            }

            if (schema.Extends != null)
            {
                foreach (JsonSchema jsonSchema in schema.Extends)
                {
                    currentNode = AddSchema(currentNode, jsonSchema);
                }
            }

            return(currentNode);
        }
Esempio n. 2
0
        public JsonSchemaNode AddSchema(JsonSchemaNode existingNode, JsonSchema schema)
        {
            string id;

            if (existingNode != null)
            {
                if (existingNode.Schemas.Contains(schema))
                {
                    return(existingNode);
                }
                id = JsonSchemaNode.GetId(existingNode.Schemas.Union(new JsonSchema[1]
                {
                    schema
                }));
            }
            else
            {
                id = JsonSchemaNode.GetId(new JsonSchema[1]
                {
                    schema
                });
            }
            if (_nodes.Contains(id))
            {
                return(_nodes[id]);
            }
            JsonSchemaNode jsonSchemaNode = (existingNode == null) ? new JsonSchemaNode(schema) : existingNode.Combine(schema);

            _nodes.Add(jsonSchemaNode);
            AddProperties(schema.Properties, jsonSchemaNode.Properties);
            AddProperties(schema.PatternProperties, jsonSchemaNode.PatternProperties);
            if (schema.Items != null)
            {
                for (int i = 0; i < schema.Items.Count; i++)
                {
                    AddItem(jsonSchemaNode, i, schema.Items[i]);
                }
            }
            if (schema.AdditionalProperties != null)
            {
                AddAdditionalProperties(jsonSchemaNode, schema.AdditionalProperties);
            }
            if (schema.Extends != null)
            {
                jsonSchemaNode = AddSchema(jsonSchemaNode, schema.Extends);
            }
            return(jsonSchemaNode);
        }