def map(cls, element: AnyElement) -> List[Class]: """Map schema children elements to classes.""" assert element.qname is not None target_namespace, module = split_qname(element.qname) target = cls.build_class(element, target_namespace) return list(ClassUtils.flatten(target, module))
def test_flatten(self): target = ClassFactory.create( qname="{xsdata}root", attrs=AttrFactory.list(3), inner=ClassFactory.list(2) ) for attr in target.attrs: attr.types.extend([x.clone() for x in attr.types]) for tp in attr.types: tp.forward = True result = ClassUtils.flatten(target, "xsdata") actual = list(result) self.assertIsInstance(result, Generator) self.assertEqual(3, len(actual)) for obj in actual: self.assertEqual("xsdata", obj.module) for attr in target.attrs: self.assertEqual(1, len(attr.types)) self.assertFalse(attr.types[0].forward)
def map(cls, data: Dict, name: str) -> List[Class]: """Convert a dictionary to a list of codegen classes.""" target = cls.build_class(data, name) return list(ClassUtils.flatten(target, name))