xsdata.reducer module

xsdata.reducer.simple_type(item)[source]
class xsdata.reducer.ClassReducer(common_types=<factory>, processed=<factory>, class_index=<factory>)[source]

Bases: object

The purpose of this class is to minimize the number of generated classes because of excess verbosity in the given xsd schema and duplicate types.

schema: Schema = None
common_types: Dict[str, Class] = None
processed: Dict = None
class_index: Dict[str, List[Class]] = None
process(schema, classes)[source]

Process class list in steps.

Steps:
  • Merge redefined classes

  • Create a class qname index

  • Mark as abstract classes with the same qname

  • Flatten classes

  • Return a final class list for code generators.

Return type

List[Class]

fetch_classes_for_generation()[source]

Return the qualified classes to continue for code generation.

The rest of the classes are stored as common types to be used later by the next schemas in the proccess.

Qualifications:
  • not an abstract

  • type: element | complexType | simpleType with enumerations

Return type

List[Class]

create_class_qname_index(classes)[source]
flatten_classes()[source]
is_self_referencing(item, dependency)[source]
Return type

bool

find_class(dependency, condition=<function simple_type>)[source]
Return type

Optional[Class]

find_common_class(qname, condition=None)[source]
find_schema_class(qname, condition=None)[source]
Return type

Optional[Class]

merge_redefined_classes(classes)[source]

Merge original and redefined classes.

mark_abstract_duplicate_classes()[source]

Search for groups with more than one class and mark as abstract any complex type with the same name as an element.

flatten_class(item)[source]

Flatten class traits from the common types registry.

Steps:
  • Enum unions

  • Parent classes

  • Attributes

  • Inner classes

flatten_enumeration_unions(item)[source]
flatten_extension(item, extension)[source]

If the extension class is found in the registry prepend it’s attributes to the given class.

The attribute list is deep cloned and each attribute type is prepended with the extension prefix if it isn’t a reference to another schema.

flatten_attribute(item, attr)[source]

If the attribute type is found in the registry overwrite the given attribute type and merge the restrictions.

If the common type doesn’t have just one attribute fallback to the default xsd type xs:string

qname(name)[source]
Return type

str

static copy_attributes(source, target, extension)[source]
static copy_inner_classes(source, target)[source]
static create_default_attribute(item, extension)[source]