Skip to content

Commit 844e357

Browse files
committed
Add permissive parsing for TypeDefinition
Before it was not possible to skip parsing of invalid TypeDefinition node.
1 parent d05d746 commit 844e357

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717
- Support for TypeDefinition in OData v4 - Martin Miksik
1818
- Support for TypeDefinition in OData v4 - Martin Miksik
1919
- Add V4 to pyodata cmd interface - Martin Miksik
20+
- Permissive parsing for TypeDefinition
2021

2122
### Changed
2223
- Implementation and naming schema of `from_etree` - Martin Miksik

pyodata/policies.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ParserError(Enum):
1717
ANNOTATION = auto()
1818
ASSOCIATION = auto()
1919

20+
TYPE_DEFINITION = auto()
2021
ENUM_TYPE = auto()
2122
ENTITY_TYPE = auto()
2223
ENTITY_SET = auto()

pyodata/v4/build_functions.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,17 @@ def build_unit_annotation(config: Config, target: Typ, annotation_node):
149149

150150

151151
def build_type_definition(config: Config, node):
152-
typ = copy.deepcopy(Types.from_name(node.get('UnderlyingType'), config))
153-
typ.name = node.get('Name')
154-
155-
annotation_nodes = node.xpath('edm:Annotation', namespaces=config.namespaces)
156-
if annotation_nodes:
157-
annotation_node = annotation_nodes[0]
158-
build_annotation(annotation_node.get('Term'), config, target=typ, annotation_node=annotation_node)
152+
try:
153+
typ = copy.deepcopy(Types.from_name(node.get('UnderlyingType'), config))
154+
typ.name = node.get('Name')
155+
156+
annotation_nodes = node.xpath('edm:Annotation', namespaces=config.namespaces)
157+
if annotation_nodes:
158+
annotation_node = annotation_nodes[0]
159+
build_annotation(annotation_node.get('Term'), config, target=typ, annotation_node=annotation_node)
160+
except KeyError as ex:
161+
config.err_policy(ParserError.TYPE_DEFINITION).resolve(ex)
162+
typ = NullType(node.get('Name'))
159163

160164
return typ
161165

0 commit comments

Comments
 (0)