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.

Steps:
  • Separate common/enumerations from class list

  • Add all common/enumerations to registry

  • Flatten the current common types

  • Flatten the generation types

Return type

List[Class]

Returns

The final list of normalized classes/enumerations

flatten_classes(classes, schema)[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, schema)[source]

Find a common type by the qualified named with the prefixed namespace if exists or the target namespace.

Return type

Optional[Class]

flatten_class(item, schema)[source]

Flatten class traits from the common types registry.

Steps:
  • Enum unions

  • Parent classes

  • Attributes

  • Inner classes

flatten_enumeration_unions(item, schema)[source]
flatten_extension(item, extension, schema)[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, schema)[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

separate_common_types(classes)[source]
static pop_classes(classes, condition)[source]

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

Return type

List[Class]

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