Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Feb 16, 2021
1 parent d19f513 commit c626ba8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions xsdata/codegen/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,39 @@ def rename_classes(self, classes: List[Class]):
total_elements = sum(x.is_element for x in classes)
for target in classes:
if not target.is_element or total_elements > 1:
self.rename_class(target)

def rename_class(self, target: Class):
if target.tag == Tag.COMPLEX_TYPE:
suffix = "Base"
else:
suffix = ""

self.rename_class(target, suffix)

def rename_class(self, target: Class, suffix):
"""Find the next available class identifier, save the original name in
the class metadata and update the class qualified name and all classes
that depend on the target class."""

qname = target.qname
namespace, name = split_qname(target.qname)
target.qname = self.next_qname(namespace, name)
target.qname = self.next_qname(namespace, name, suffix)
target.meta_name = name
self.container.reset(target, qname)

for item in self.container.iterate():
self.rename_class_dependencies(item, qname, target.qname)

def next_qname(self, namespace: str, name: str) -> str:
def next_qname(self, namespace: str, name: str, suffix: str) -> str:
"""Append the next available index number for the given namespace and
local name."""
index = 0

reserved = set(map(alnum, self.container.data.keys()))
if suffix:
qname = build_qname(namespace, f"{name}_{suffix}")
if alnum(qname) not in reserved:
return qname

index = 0
while True:
index += 1
qname = build_qname(namespace, f"{name}_{index}")
Expand All @@ -217,7 +229,7 @@ def rename_attr_dependencies(self, attr: Attr, search: str, replace: str):
"""Search and replace the old qualified attribute type name with the
new one in the attr types, choices and default value."""
for attr_type in attr.types:
if attr_type.qname == search:
if not attr_type.forward and attr_type.qname == search:
attr_type.qname = replace

if isinstance(attr.default, str) and attr.default.startswith("@enum@"):
Expand Down
2 changes: 1 addition & 1 deletion xsdata/codegen/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def find_circular_group(cls, target: Class) -> Optional[Attr]:
def mark_strict_types(cls, classes: List[Class]):
"""If there is a class derived from xs:element update all
xs:complexTypes derived classes as strict types."""

return
try:
element = next(obj for obj in classes if obj.is_element)
for obj in classes:
Expand Down

0 comments on commit c626ba8

Please sign in to comment.