xsdata.reducer module

class xsdata.reducer.ClassReducer(common_types=<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.

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

Process class list in steps.

  • Separate common/enumerations from class list

  • Add all common/enumerations to registry

  • Flatten the current common types

  • Flatten the generation types

Return type



The final list of normalized classes/enumerations

flatten_classes(classes, nsmap)[source]
add_common_types(classes, namespace)[source]

Add class to the common types registry with its qualified name with the target namespace.

find_common_type(name, nsmap)[source]

Find a common type by the qualified named with the namespace prefix.

Return type


flatten_class(item, nsmap)[source]

Flatten class traits from the common types registry.

  • Parent classes

  • Attributes

  • Inner classes

flatten_extension(item, extension, nsmap)[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.

static copy_attributes(source, target, extension)[source]
flatten_attribute(attr, nsmap)[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

static pop_classes(classes, condition)[source]

Pop and return the objects matching the given condition from the given list of of classes.

Return type