xsdata.codegen.sanitizer module¶
-
class
xsdata.codegen.sanitizer.
ClassSanitizer
(container)[source]¶ Bases:
object
Prepare all the classes attributes for code generation and cleanup after the analyzer processors.
- Parameters
container (
ClassContainer
) –
-
container
: ClassContainer¶
-
classmethod
process
(container)[source]¶ Iterate through all classes and run the sanitizer procedure.
- Parameters
container (
ClassContainer
) –
-
process_class
(target)[source]¶ Sanitize the attributes of the given class. After applying all the flattening handlers the attributes need to be further sanitized to squash common issues like duplicate attribute names.
- Steps:
Sanitize inner classes
Sanitize attributes default value
Sanitize attributes name
Sanitize attributes sequential flag
Sanitize duplicate attribute names
- Parameters
target (
Class
) –
-
process_attribute_default
(target, attr)[source]¶ Sanitize attribute default value.
- Cases:
List fields can not have a fixed value.
Optional fields or xsi:type can not have a default or fixed value.
Convert string literal default value for enum fields.
-
process_attribute_default_enum
(target, attr)[source]¶ Convert string literal default value for enum fields.
Loop through all attributes types and search for enum sources. If an enum source exist map the default string literal value to a qualified name. If the source class in inner promote it to root classes.
-
promote_inner_class
(parent, inner)[source]¶ Convert inner class to root class.
- Steps:
Remove inner class from parent
Prepend parent name to inner class name.
Search and replace all matching attribute types.
Add inner class to the global class index.
-
classmethod
process_attribute_restrictions
(attr)[source]¶ Sanitize attribute required flag by comparing the min/max occurrences restrictions.
- Parameters
attr (
Attr
) –
-
classmethod
process_attribute_sequence
(target, attr)[source]¶ Reset the attribute at the given index if it has no siblings with the sequential restriction.
-
classmethod
process_attribute_name
(attr)[source]¶ Sanitize attribute name in preparation for duplicate attribute names handler.
- Steps:
Remove non alpha numerical values
Handle Enum negative numerical values
Remove namespaces prefixes
Ensure name not empty
Ensure name starts with a letter
- Parameters
attr (
Attr
) –
-
classmethod
process_duplicate_attribute_names
(attrs)[source]¶ Sanitize duplicate attribute names that might exist by applying rename strategies.
- Steps:
1. If more than two attributes share the same name or if they are enumerations append a numerical index to the attribute names. 2. If one of the two fields has a specific namespace prepend it to the name. If possible rename the second field. 3. Append the xml type to the name of one of the two attributes. if possible rename the second field or the field with xml type attribute.