Skip to content

Commit a61d9b3

Browse files
committed
examples: JSON example: deduplicate field names for now
1 parent 3578e75 commit a61d9b3

3 files changed

Lines changed: 15 additions & 28 deletions

File tree

reqif/experimental/reqif_schema.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, reqif_bundle: ReqIFBundle):
3131
assert reqif_bundle.core_content is not None
3232
assert reqif_bundle.core_content.req_if_content is not None
3333
assert reqif_bundle.core_content.req_if_content.spec_types is not None
34+
3435
for spec_type in reqif_bundle.core_content.req_if_content.spec_types:
3536
if not isinstance(spec_type, ReqIFSpecObjectType):
3637
continue
@@ -84,3 +85,11 @@ def is_spec_object_a_heading(self, spec_object: ReqIFSpecObject):
8485
# could be detected, assume that all spec objects in the ReqIF file are
8586
# simply requirements.
8687
return False
88+
89+
def iterate_unique_field_names(self):
90+
unique_names_so_far = set()
91+
for attribute_definition_ in self.spec_object_type_attributes.values():
92+
if attribute_definition_.long_name in unique_names_so_far:
93+
continue
94+
unique_names_so_far.add(attribute_definition_.long_name)
95+
yield attribute_definition_.long_name, attribute_definition_.attribute_type.name

tests/integration/examples/04_convert_reqif_to_json/expected/sample1_polarion.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@
3030
}
3131
],
3232
"fields": [
33-
{
34-
"name": "ReqIF.ChapterName",
35-
"type": "STRING"
36-
},
37-
{
38-
"name": "ReqIF.ForeignCreatedBy",
39-
"type": "STRING"
40-
},
41-
{
42-
"name": "ReqIF.ForeignCreatedOn",
43-
"type": "DATE"
44-
},
45-
{
46-
"name": "ReqIF.ForeignID",
47-
"type": "STRING"
48-
},
49-
{
50-
"name": "ReqIF.Text",
51-
"type": "XHTML"
52-
},
5333
{
5434
"name": "ReqIF.ChapterName",
5535
"type": "STRING"

tests/integration/examples/04_convert_reqif_to_json/script.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ def convert(reqif_bundle: ReqIFBundle) -> ReqDict:
7777
# field names available in the ReqIF file.
7878
# NOTE: This can create many unused columns if the requirements and
7979
# chapters attributes are two distinct sets of fields.
80-
reqif_dict.fields = []
81-
reqif_dict.fields.extend(
80+
reqif_dict.fields = list(
8281
map(
83-
lambda attribute_definition_:
84-
{
85-
"name": attribute_definition_.long_name,
86-
"type": attribute_definition_.attribute_type.name
87-
},
88-
reqif_schema.spec_object_type_attributes.values()
82+
lambda attribute_tuple_: {
83+
"name": attribute_tuple_[0],
84+
"type": attribute_tuple_[1],
85+
},
86+
reqif_schema.iterate_unique_field_names(),
8987
)
9088
)
9189

0 commit comments

Comments
 (0)