コード例 #1
0
        private void ExtractProperties(XmlSchema xsdSchema, string name, JsonSchema jSchema)
        {
            if (jSchema == JsonSchema.Empty)
            {
                // empty type,
                XmlSchemaComplexType complexType = new XmlSchemaComplexType
                {
                    Name = name,
                };

                xsdSchema.Items.Add(complexType);
            }
            else if (jSchema.Properties() != null || jSchema.AllOf() != null || jSchema.OneOf() != null)
            {
                if (SimpleContent(jSchema))
                {
                    XmlSchemaComplexType complexType = ExtractComplexTypeSimpleContent(name, jSchema);
                    xsdSchema.Items.Add(complexType);
                }
                else
                {
                    XmlSchemaComplexType complexType = ExtractComplexType(name, jSchema);
                    xsdSchema.Items.Add(complexType);
                }
            }
            else
            {
                XmlSchemaSimpleType simpleType = ExtractSimpleType(name, jSchema);
                xsdSchema.Items.Add(simpleType);
            }
        }
コード例 #2
0
        private void FollowRef(string path, JsonSchema jSchema, ISet <string> alreadyVisitedTypes, string parentXpath)
        {
            string reference = jSchema.Ref();

            if (reference != null)
            {
                string     typeName = ExtractTypeNameFromDefinitionReference(reference);
                JsonSchema schema   = definitions.GetValueOrDefault(typeName);
                if (schema != null)
                {
                    if (alreadyVisitedTypes.Contains(typeName))
                    {
                        return;
                    }

                    ISet <string> currentlyVisitedTypes = new HashSet <string>(alreadyVisitedTypes);
                    currentlyVisitedTypes.Add(typeName);

                    if (schema.Properties() != null)
                    {
                        foreach (KeyValuePair <string, JsonSchema> def in schema.Properties())
                        {
                            TraverseModell(path, typeName, def.Key, def.Value, IsRequired(def.Key, schema), currentlyVisitedTypes, jSchema, parentXpath);
                        }
                    }
                    else if (schema.OneOf() != null)
                    {
                        foreach (JsonSchema oneOfSchema in schema.OneOf())
                        {
                            if (oneOfSchema.Ref() != null)
                            {
                                FollowRef(path, oneOfSchema, currentlyVisitedTypes, parentXpath);
                            }
                            else if (oneOfSchema.Properties() != null)
                            {
                                foreach (KeyValuePair <string, JsonSchema> def in oneOfSchema.Properties())
                                {
                                    TraverseModell(path, typeName, def.Key, def.Value, IsRequired(def.Key, oneOfSchema), currentlyVisitedTypes, jSchema, parentXpath);
                                }
                            }
                        }
                    }
                    else if (schema.AllOf() != null)
                    {
                        foreach (JsonSchema allOfSchema in schema.AllOf())
                        {
                            if (allOfSchema.Ref() != null)
                            {
                                FollowRef(path, allOfSchema, currentlyVisitedTypes, parentXpath);
                            }
                            else if (allOfSchema.Properties() != null)
                            {
                                foreach (KeyValuePair <string, JsonSchema> def in allOfSchema.Properties())
                                {
                                    TraverseModell(path, typeName, def.Key, def.Value, IsRequired(def.Key, allOfSchema), currentlyVisitedTypes, jSchema, parentXpath);
                                }
                            }
                        }
                    }
                }
            }
        }