Skip to content

Commit

Permalink
Merge pull request #727 from tefra/ignore-patterns
Browse files Browse the repository at this point in the history
feat: Add option to ignore xml pattern restrictions
  • Loading branch information
tefra authored Dec 11, 2022
2 parents 152876d + 8114c4d commit 351464d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/codegen/handlers/test_process_attributes_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ def test_process_types(self, mock_process_type):

self.assertEqual(types[:-1], attr.types)

def test_process_types_with_ignore_patterns(self):
target = ClassFactory.create()
attr = AttrFactory.native(DataType.DECIMAL)
attr.restrictions.pattern = r"\d{2}.\d{2}"

self.processor.container.config.output.ignore_patterns = True
self.processor.process_types(target, attr)
self.assertEqual(DataType.DECIMAL, attr.types[0].datatype)

def test_cascade_properties(self):
target = ClassFactory.create(default="2", fixed=True, nillable=True)
attr = AttrFactory.native(DataType.STRING, tag=Tag.EXTENSION)
Expand Down
2 changes: 2 additions & 0 deletions tests/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_create(self):
' <CompoundFields defaultName="choice" forceDefaultName="false">false</CompoundFields>\n'
" <PostponedAnnotations>false</PostponedAnnotations>\n"
" <UnnestClasses>false</UnnestClasses>\n"
" <IgnorePatterns>false</IgnorePatterns>\n"
" </Output>\n"
" <Conventions>\n"
' <ClassName case="pascalCase" safePrefix="type"/>\n'
Expand Down Expand Up @@ -97,6 +98,7 @@ def test_read(self):
' <CompoundFields defaultName="choice" forceDefaultName="false">false</CompoundFields>\n'
" <PostponedAnnotations>false</PostponedAnnotations>\n"
" <UnnestClasses>false</UnnestClasses>\n"
" <IgnorePatterns>false</IgnorePatterns>\n"
" </Output>\n"
" <Conventions>\n"
' <ClassName case="pascalCase" safePrefix="type"/>\n'
Expand Down
3 changes: 3 additions & 0 deletions xsdata/codegen/handlers/process_attributes_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def process(self, target: Class):

def process_types(self, target: Class, attr: Attr):
"""Process every attr type and filter out duplicates."""
if self.container.config.output.ignore_patterns:
attr.restrictions.pattern = None

for attr_type in list(attr.types):
self.process_type(target, attr, attr_type)

Expand Down
2 changes: 2 additions & 0 deletions xsdata/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class GeneratorOutput:
:param postponed_annotations: Enable postponed evaluation of annotations,
default: false, python>=3.7 Only
:param unnest_classes: Move inner classes to upper level, default: false
:param ignore_patterns: Ignore pattern restrictions, default: false
"""

package: str = element(default="generated")
Expand All @@ -261,6 +262,7 @@ class GeneratorOutput:
max_line_length: int = attribute(default=79)
postponed_annotations: bool = element(default=False)
unnest_classes: bool = element(default=False)
ignore_patterns: bool = element(default=False)

def update(self, **kwargs: Any):
objects.update(self, **kwargs)
Expand Down

0 comments on commit 351464d

Please sign in to comment.