Beispiel #1
0
    def process_attribute_restrictions(cls, attr: Attr):
        """Sanitize attribute required flag by comparing the min/max
        occurrences restrictions."""
        restrictions = attr.restrictions
        min_occurs = restrictions.min_occurs or 0
        max_occurs = restrictions.max_occurs or 0

        if attr.is_attribute:
            restrictions.min_occurs = None
            restrictions.max_occurs = None
        elif attr.is_tokens:
            restrictions.required = None
            if max_occurs <= 1:
                restrictions.min_occurs = None
                restrictions.max_occurs = None
        elif attr.xml_type is None or min_occurs == max_occurs == 1:
            restrictions.required = True
            restrictions.min_occurs = None
            restrictions.max_occurs = None
        elif min_occurs == 0 and max_occurs < 2:
            restrictions.required = None
            restrictions.min_occurs = None
            restrictions.max_occurs = None
            attr.default = None
            attr.fixed = False
        else:  # max_occurs > 1
            restrictions.min_occurs = min_occurs
            restrictions.required = None
            attr.fixed = False

        if attr.default or attr.fixed or attr.restrictions.nillable:
            restrictions.required = None
Beispiel #2
0
    def process_attribute_default(self, target: Class, attr: Attr):
        """
        Sanitize attribute default value.

        Cases:
            1. List fields can not have a fixed value.
            2. Optional fields or xsi:type can not have a default or fixed value.
            3. Convert string literal default value for enum fields.
        """
        if attr.is_list:
            attr.fixed = False

        if attr.is_optional or attr.is_xsi_type:
            attr.fixed = False
            attr.default = None

        if attr.default and not attr.is_enumeration:
            self.process_attribute_default_enum(target, attr)