Commit 41e7da9a authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Fixes error in generated typescript

parent c17e08eb0764
......@@ -62,6 +62,21 @@ class TsSchemaGenerator:
"""
self._slices.append(text)
@staticmethod
def _relation_is_inherited(entity, relation):
"""
Determines whether a relation has been inherited
:param entity: The current type of entity
:param relation: The relation
:return: Whether the relation is inherited
"""
subjects = relation.subjects(None)
ancestors = entity.ancestors()
for ancestor in ancestors:
if ancestor in subjects:
return True
return False
def _handle_attribute(self, entity, relation):
"""
Handles an attribute for a entity type
......@@ -69,6 +84,8 @@ class TsSchemaGenerator:
:param relation: The attribute
:return: Nothing
"""
if TsSchemaGenerator._relation_is_inherited(entity, relation):
return
if relation.description is not None and len(relation.description) > 0:
self._print(" /**\n")
self._print(" * %s\n" % relation.description)
......@@ -88,6 +105,8 @@ class TsSchemaGenerator:
:param relation: The relation
:return: Nothing
"""
if TsSchemaGenerator._relation_is_inherited(entity, relation):
return
objects = relation.objects(entity.type)
for object_type in objects:
if relation.description is not None and len(relation.description) > 0:
......@@ -128,6 +147,7 @@ class TsSchemaGenerator:
if parent is not None:
self._print(" extends %s" % parent.type)
self._print(" {\n")
all_relations = []
for relation in entity.subject_relations():
if relation.type == "eid":
self._handle_attribute(entity, relation)
......@@ -135,8 +155,11 @@ class TsSchemaGenerator:
self._handle_attribute(entity, relation)
else:
self._handle_relation_subject(entity, relation)
all_relations.append(relation)
for relation in entity.object_relations():
self._handle_relation_object(entity, relation)
if relation not in all_relations:
# avoid reflexive relations already handled in subjects
self._handle_relation_object(entity, relation)
self._print("}\n\n")
def generate(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment