private void AddInfo(XmlSchema xSchema, JsonSchema jSchema) { InfoKeyword info = jSchema.Get<InfoKeyword>(); if (info != null) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); XmlSchemaDocumentation documentation = new XmlSchemaDocumentation(); annotation.Items.Add(documentation); List<XmlElement> elements = new List<XmlElement>(); JsonObject infoObject = info.ToJson(new JsonSerializer()).Object; foreach (string attributeName in infoObject.Keys) { XmlElement attrElement = xmlDocument.CreateElement("xs", "attribute", XML_SCHEMA_NS); attrElement.SetAttribute("name", attributeName); attrElement.SetAttribute("fixed", infoObject.TryGetString(attributeName)); elements.Add(attrElement); } documentation.Markup = elements.ToArray(); xSchema.Items.Add(annotation); } }
/// <summary> /// Add a named text to the <code>info</code> keyword. /// </summary> /// <param name="schema">Json Schema to add text to</param> /// <param name="name">Name for text</param> /// <param name="text">Actual text</param> /// <returns>schema containing new text</returns> public static JsonSchema Info(this JsonSchema schema, string name, string text) { var keyword = schema.OfType <InfoKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new InfoKeyword(); schema.Add(keyword); } keyword.Add(name, text); return(schema); }
private static void KeywordEqual(InfoKeyword expected, InfoKeyword actual) { Assert.True(expected.Value.IsEquivalentTo(actual.Value)); }