Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to keep SimpleTypes #935

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/models/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_create(self):
' <ConstantName case="screamingSnakeCase" safePrefix="value"/>\n'
' <ModuleName case="snakeCase" safePrefix="mod"/>\n'
' <PackageName case="snakeCase" safePrefix="pkg"/>\n'
" </Conventions>\n"
" </Conventions>\n"
" <Substitutions>\n"
' <Substitution type="package" search="http://www.w3.org/2001/XMLSchema" replace="xs"/>\n'
' <Substitution type="package" search="http://www.w3.org/XML/1998/namespace" replace="xml"/>\n'
Expand All @@ -64,6 +64,7 @@ def test_create(self):
' <Substitution type="class" search="(.*)Class$" replace="\\1Type"/>\n'
" </Substitutions>\n"
" <Extensions/>\n"
" <TypesToKeep/>\n"
"</Config>\n"
)
self.assertEqual(expected, file_path.read_text())
Expand All @@ -81,6 +82,7 @@ def test_read(self):
" </Conventions>\n"
" <Aliases/>\n"
" <Substitutions/>\n"
" <TypesToKeep/>\n"
"</Config>\n"
)
file_path = Path(tempfile.mktemp())
Expand Down Expand Up @@ -116,6 +118,7 @@ def test_read(self):
" <Aliases/>\n"
" <Substitutions/>\n"
" <Extensions/>\n"
" <TypesToKeep/>\n"
"</Config>\n"
)
self.assertEqual(expected, file_path.read_text())
Expand Down
19 changes: 19 additions & 0 deletions xsdata/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,24 @@ class GeneratorExtensions:

extension: List[GeneratorExtension] = array_element()

@dataclass
class GeneratorSimpleType:
"""
SimpleType to keep

:param type: The target object type
"""

type: ObjectType = attribute(required=True)

@dataclass
class GeneratorTypesKeeping:
"""
Generator simple types keeping.

:param types: The list of types to keep
"""
simple_types: List[GeneratorSimpleType] = array_element()

@dataclass
class GeneratorConfig:
Expand Down Expand Up @@ -520,6 +538,7 @@ class Meta:
default_factory=GeneratorSubstitutions
)
extensions: GeneratorExtensions = element(default_factory=GeneratorExtensions)
types_to_keep: GeneratorTypesKeeping = element(default_factory=GeneratorTypesKeeping)

def __post_init__(self):
if self.aliases:
Expand Down
Loading