Skip to content

Commit

Permalink
Reset min occurs only for multi element choices (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra authored Jul 16, 2023
1 parent 68d5071 commit 9a894ae
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions xsdata/codegen/handlers/create_compound_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9a894ae

Please sign in to comment.