From 9a894ae09207f9d1d93107ca0e86fe1cf8d530be Mon Sep 17 00:00:00 2001 From: Chris Tsou Date: Sun, 16 Jul 2023 13:17:39 +0300 Subject: [PATCH] Reset min occurs only for multi element choices (#828) --- .../handlers/create_compound_fields.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/xsdata/codegen/handlers/create_compound_fields.py b/xsdata/codegen/handlers/create_compound_fields.py index d4432b5a..5735bb11 100644 --- a/xsdata/codegen/handlers/create_compound_fields.py +++ b/xsdata/codegen/handlers/create_compound_fields.py @@ -35,22 +35,21 @@ def __init__(self, container: ContainerInterface): self.config = container.config.output.compound_fields def process(self, target: Class): - if self.config.enabled: - groups = group_by(target.attrs, get_restriction_choice) - for choice, attrs in groups.items(): - if choice and len(attrs) > 1: + groups = group_by(target.attrs, get_restriction_choice) + for choice, attrs in groups.items(): + if choice and len(attrs) > 1: + if self.config.enabled: self.group_fields(target, attrs) - else: - for attr in target.attrs: - if attr.restrictions.choice: - self.calculate_choice_min_occurs(attr) + else: + self.calculate_choice_min_occurs(attrs) @classmethod - def calculate_choice_min_occurs(cls, attr: Attr): - for path in attr.restrictions.path: - name, index, mi, ma = path - if name == CHOICE and mi <= 1: - attr.restrictions.min_occurs = 0 + def calculate_choice_min_occurs(cls, attrs: List[Attr]): + for attr in attrs: + for path in attr.restrictions.path: + name, index, mi, ma = path + if name == CHOICE and mi <= 1: + attr.restrictions.min_occurs = 0 @classmethod def update_counters(cls, attr: Attr, counters: Dict):