def flatten_attribute_types(self, target: Class, attr: Attr): """ Loop over the the given attribute types to flatten simple definitions. Notes: * xs:pattern is not yet supported reset all native types to xs:string. * skip over forward references aka inner classes """ for current_type in list(attr.types): if current_type.native: if attr.restrictions.pattern: self.reset_attribute_type(current_type) elif not current_type.forward_ref: self.flatten_attribute_type(target, attr, current_type) attr.types = unique_sequence(attr.types, key="name")
def flatten_attribute_types(self, target: Class, attr: Attr): """ Flatten attribute types by using the source attribute type. Steps: * Skip xsd native types * Detect circular references if no source is found * Skip enumeration types * Overwrite attribute type from source """ types = [] for attr_type in attr.types: source = None if not attr_type.native: type_qname = target.source_qname(attr_type.name) source = self.find_class(type_qname) if source is None: attr_type.self_ref = self.attr_depends_on(attr_type, target) types.append(attr_type) elif self.is_qname(source): types.append(source.extensions[0].type.clone()) elif source.is_enumeration: types.append(attr_type) elif len(source.attrs) == 1: source_attr = source.attrs[0] types.extend(source_attr.types) restrictions = source_attr.restrictions.clone() restrictions.merge(attr.restrictions) attr.restrictions = restrictions self.copy_inner_classes(source, target) else: types.append(AttrType(name=DataType.STRING.code, native=True)) logger.warning("Missing type implementation: %s", source.type.__name__) attr.types = types