@@ -30,7 +30,7 @@ def _is_list_content_homogenous_type(list_):
30
30
return result
31
31
32
32
33
- def _prop_for_spec (prop_spec , stix_version ):
33
+ def _prop_for_spec (prop_name , prop_spec , stix_version ):
34
34
"""
35
35
Given an object generator spec, which is treated as a spec for a property
36
36
value of an object, determine the type of value the spec generates and
@@ -45,8 +45,11 @@ def _prop_for_spec(prop_spec, stix_version):
45
45
)
46
46
47
47
if prop_spec_type in _JSON_SIMPLE_TYPE_STIX_PROPERTY_MAP :
48
- prop_class = _JSON_SIMPLE_TYPE_STIX_PROPERTY_MAP [prop_spec_type ]
49
- prop_obj = prop_class ()
48
+ if "ref" in prop_name or "refs" in prop_name :
49
+ prop_obj = stix2 .properties .ReferenceProperty (valid_types = prop_spec ['stix-type' ])
50
+ else :
51
+ prop_class = _JSON_SIMPLE_TYPE_STIX_PROPERTY_MAP [prop_spec_type ]
52
+ prop_obj = prop_class ()
50
53
51
54
elif prop_spec_type == "object" :
52
55
# DictionaryProperty needs a spec_version parameter.
@@ -63,21 +66,23 @@ def _prop_for_spec(prop_spec, stix_version):
63
66
raise stix2generator .exceptions .EmptyListError ()
64
67
if not _is_list_content_homogenous_type (prop_spec ):
65
68
raise stix2generator .exceptions .HeterogenousListError (prop_spec )
66
-
67
69
element_spec = prop_spec [0 ]
68
70
69
71
else :
70
72
element_spec = prop_spec ["items" ]
71
73
72
- element_prop_obj = _prop_for_spec (element_spec , stix_version )
73
- prop_obj = stix2 .properties .ListProperty (element_prop_obj )
74
+ element_prop_obj = _prop_for_spec ("" , element_spec , stix_version )
75
+
76
+ if "ref" in prop_name or "refs" in prop_name :
77
+ prop_obj = stix2 .properties .ListProperty (stix2 .properties .ReferenceProperty (valid_types = element_spec ["stix-type" ], spec_version = '2.1' ))
78
+ else :
79
+ prop_obj = stix2 .properties .ListProperty (element_prop_obj )
74
80
75
81
else :
76
82
# Maybe we just hit this for "null" specs?
77
83
raise stix2generator .exceptions .IllegalSTIXObjectPropertyType (
78
84
prop_spec_type
79
85
)
80
-
81
86
return prop_obj
82
87
83
88
@@ -110,7 +115,7 @@ def stix2_register_custom(spec, obj_type_name, stix_version):
110
115
prop_specs = spec .get ("properties" , {})
111
116
112
117
prop_map = [
113
- (prop_name , _prop_for_spec (prop_spec , stix_version ))
118
+ (prop_name , _prop_for_spec (prop_name , prop_spec , stix_version ))
114
119
for prop_name , prop_spec in prop_specs .items ()
115
120
]
116
121
0 commit comments