private void AddCustomNameSpaces(XmlSchema xsdSchema, JsonSchema jsonSchema) { Dictionary <string, JsonSchema> definitions = GetterExtensions.Definitions(jsonSchema); if (definitions != null) { foreach (KeyValuePair <string, JsonSchema> def in definitions) { JsonSchema jSchema = def.Value; if (jSchema != JsonSchema.Empty && jSchema.Properties() != null) { Dictionary <string, JsonSchema> props = jSchema.Properties(); foreach (KeyValuePair <string, JsonSchema> property in props) { JsonSchema schemaProp = property.Value; string nameProp = property.Key; if (nameProp.Equals("dataFormatProvider") && schemaProp.Const().String.Equals("SERES")) { xsdSchema.Namespaces.Add("seres", SERES_NS); } } } } } }
/// <summary> /// Creates a XmlSchema object from a JSON Schema object /// </summary> /// <param name="jSchema">The Json Schema to convert</param> /// <returns>The converted XmlSchema object</returns> public XmlSchema CreateXsd(JsonSchema jSchema) { if (jSchema == null) { throw new Exception("Cannot create XSD from empty (null) JsonSchema"); } XmlSchema xsdSchema = new XmlSchema { ElementFormDefault = XmlSchemaForm.Qualified, AttributeFormDefault = XmlSchemaForm.Unqualified, }; xsdSchema.Namespaces.Add("brreg", BRREG_NS); AddInfo(xsdSchema, jSchema); string title = GetterExtensions.Title(jSchema); string description = GetterExtensions.Description(jSchema); if (!string.IsNullOrEmpty(title) || !string.IsNullOrEmpty(description)) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); AddTitleAndDescriptionAnnotations(jSchema, annotation); xsdSchema.Items.Add(annotation); } // Handle global element declarations Dictionary <string, JsonSchema> globalProperties = jSchema.Properties(); if (globalProperties != null) { foreach (KeyValuePair <string, JsonSchema> property in globalProperties) { XmlSchemaElement rootElement = new XmlSchemaElement { Name = property.Key, SchemaTypeName = GetTypeName(property.Value), }; AddAnnotations(rootElement, property.Value); xsdSchema.Items.Add(rootElement); } } // Handle all definitions Dictionary <string, JsonSchema> definitions = GetterExtensions.Definitions(jSchema); if (definitions != null) { foreach (KeyValuePair <string, JsonSchema> def in definitions) { ExtractProperties(xsdSchema, def.Key, def.Value); } } return(xsdSchema); }