Skip to content

Commit

Permalink
Avoid reseting required flag on xs:attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Feb 25, 2023
1 parent 3f8af45 commit fa51f61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion xsdata/codegen/handlers/create_compound_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict
from typing import Dict
from typing import List
from typing import Set

from xsdata.codegen.mixins import ContainerInterface
from xsdata.codegen.mixins import RelativeHandlerInterface
Expand Down Expand Up @@ -90,7 +91,7 @@ def choose_name(self, target: Class, names: List[str]) -> str:
reserved = self.build_reserved_names(target, names)
return ClassUtils.unique_name(name, reserved)

def build_reserved_names(self, target: Class, names: List[str]) -> set[str]:
def build_reserved_names(self, target: Class, names: List[str]) -> Set[str]:
names_counter = Counter(names)
all_attrs = self.base_attrs(target)
all_attrs.extend(target.attrs)
Expand Down
10 changes: 7 additions & 3 deletions xsdata/codegen/handlers/sanitize_attributes_default_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ def should_reset_required(cls, attr: Attr) -> bool:
"""
Return whether the min occurrences for the attr needs to be reset.
Cases:
1. xs:any(Simple)Type, with no default value that's not a list already!
@Todo figure out if wildcards are supposed to be optional!
"""
return attr.default is None and object in attr.native_types and not attr.is_list
return (
not attr.is_attribute
and attr.default is None
and object in attr.native_types
and not attr.is_list
)

@classmethod
def should_reset_default(cls, attr: Attr) -> bool:
Expand Down

0 comments on commit fa51f61

Please sign in to comment.