Skip to content

Commit 7c10d89

Browse files
authored
Merge pull request #158 from strictdoc-project/stanislaw/examples
examples: JSON example: add field types
2 parents 6b745ff + a61d9b3 commit 7c10d89

6 files changed

Lines changed: 92 additions & 29 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: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@
3030
}
3131
],
3232
"fields": [
33-
"ReqIF.ChapterName",
34-
"ReqIF.ForeignCreatedBy",
35-
"ReqIF.ForeignCreatedOn",
36-
"ReqIF.ForeignID",
37-
"ReqIF.Text",
38-
"Status"
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+
},
53+
{
54+
"name": "Status",
55+
"type": "ENUMERATION"
56+
}
3957
]
4058
}

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,41 @@
167167
}
168168
],
169169
"fields": [
170-
"ReqIF.ForeignID",
171-
"LEVEL",
172-
"STATUS",
173-
"TAGS",
174-
"ReqIF.Name",
175-
"ReqIF.Text",
176-
"RATIONALE",
177-
"NOTES",
178-
"ReqIF.ChapterName"
170+
{
171+
"name": "ReqIF.ForeignID",
172+
"type": "STRING"
173+
},
174+
{
175+
"name": "LEVEL",
176+
"type": "STRING"
177+
},
178+
{
179+
"name": "STATUS",
180+
"type": "STRING"
181+
},
182+
{
183+
"name": "TAGS",
184+
"type": "STRING"
185+
},
186+
{
187+
"name": "ReqIF.Name",
188+
"type": "STRING"
189+
},
190+
{
191+
"name": "ReqIF.Text",
192+
"type": "STRING"
193+
},
194+
{
195+
"name": "RATIONALE",
196+
"type": "STRING"
197+
},
198+
{
199+
"name": "NOTES",
200+
"type": "STRING"
201+
},
202+
{
203+
"name": "ReqIF.ChapterName",
204+
"type": "STRING"
205+
}
179206
]
180207
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,21 @@
7777
}
7878
],
7979
"fields": [
80-
"ReqIF.Name",
81-
"A1",
82-
"A2",
83-
"E1"
80+
{
81+
"name": "ReqIF.Name",
82+
"type": "XHTML"
83+
},
84+
{
85+
"name": "A1",
86+
"type": "STRING"
87+
},
88+
{
89+
"name": "A2",
90+
"type": "STRING"
91+
},
92+
{
93+
"name": "E1",
94+
"type": "ENUMERATION"
95+
}
8496
]
8597
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +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(
82-
list(
83-
{
84-
attribute_definition_.long_name: 1
85-
for attribute_definition_ in reqif_schema.spec_object_type_attributes.values()
86-
}.keys()
80+
reqif_dict.fields = list(
81+
map(
82+
lambda attribute_tuple_: {
83+
"name": attribute_tuple_[0],
84+
"type": attribute_tuple_[1],
85+
},
86+
reqif_schema.iterate_unique_field_names(),
8787
)
8888
)
8989

tests/integration/examples/04_convert_reqif_to_json/test.itest

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ RUN: %diff %S/expected/sample1_polarion.json %S/Output/reqif_stdout/sample1_pola
1919

2020
RUN: python %S/script.py %S/sample_polarion_reqifz.reqifz --output-dir %S/Output/reqifz
2121
RUN: %diff %S/expected/sample1_polarion.json %S/Output/reqifz/sample1_polarion.reqif.json
22-
23-
TODO:
24-
- Type fields

0 commit comments

Comments
 (0)