Skip to content

Commit 2aad83c

Browse files
authored
Add custom property arrayType (#902)
1 parent 865c664 commit 2aad83c

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

src/rpdk/core/data/schema/base.definition.schema.v1.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
"type": "boolean",
6262
"default": true
6363
},
64+
"arrayType": {
65+
"description": "When set to AttributeList, it indicates that the array is of nested type objects, and when set to Standard it indicates that the array consists of primitive types",
66+
"type": "string",
67+
"default": "Standard",
68+
"enum": [
69+
"Standard",
70+
"AttributeList"
71+
]
72+
},
6473
"$ref": {
6574
"$ref": "http://json-schema.org/draft-07/schema#/properties/$ref"
6675
},

src/rpdk/core/data/schema/provider.definition.schema.modules.v1.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@
9696
"type": "boolean",
9797
"default": true
9898
},
99+
"arrayType": {
100+
"description": "When set to AttributeList, it indicates that the array is of nested type objects, and when set to Standard it indicates that the array consists of primitive types",
101+
"type": "string",
102+
"default": "Standard",
103+
"enum": [
104+
"Standard",
105+
"AttributeList"
106+
]
107+
},
99108
"$ref": {
100109
"$ref": "https://json-schema.org/draft-07/schema#/properties/$ref"
101110
},

src/rpdk/core/data_loaders.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ def load_resource_spec(resource_spec_file): # pylint: disable=R # noqa: C901
179179
"Explicitly specify value for insertionOrder for array: %s",
180180
property_name,
181181
)
182+
if property_type != "array" and "arrayType" in property_keywords:
183+
raise SpecValidationError(
184+
"arrayType is only applicable for properties of type array"
185+
)
182186
keyword_mappings = [
183187
(
184188
{"integer", "number"},

tests/test_data_loaders.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,101 @@ def test_load_hook_spec_hook_permissions_valid():
267267
assert result == schema
268268

269269

270+
def test_load_resource_spec_array_type_invalid():
271+
schema = {
272+
"typeName": "AWS::FOO::BAR",
273+
"description": "test schema",
274+
"additionalProperties": False,
275+
"properties": {
276+
"Foo": {
277+
"type": "array",
278+
"uniqueItems": False,
279+
"insertionOrder": False,
280+
"items": {"$ref": "#/definitions/XYZ"},
281+
},
282+
"Bar": {"type": "string", "arrayType": "Standard"},
283+
},
284+
"definitions": {
285+
"XYZ": {
286+
"type": "object",
287+
"additionalProperties": False,
288+
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
289+
}
290+
},
291+
"primaryIdentifier": ["/properties/Foo"],
292+
"readOnlyProperties": ["/properties/Foo"],
293+
"createOnlyProperties": ["/properties/Foo"],
294+
"conditionalCreateOnlyProperties": ["/properties/Bar"],
295+
}
296+
with pytest.raises(SpecValidationError) as excinfo:
297+
load_resource_spec(json_s(schema))
298+
assert (
299+
str(excinfo.value)
300+
== "arrayType is only applicable for properties of type array"
301+
)
302+
303+
304+
def test_load_resource_spec_array_type_valid():
305+
schema = {
306+
"typeName": "AWS::FOO::BAR",
307+
"description": "test schema",
308+
"additionalProperties": False,
309+
"properties": {
310+
"Foo": {
311+
"type": "array",
312+
"uniqueItems": False,
313+
"insertionOrder": False,
314+
"arrayType": "Standard",
315+
"items": {"$ref": "#/definitions/XYZ"},
316+
},
317+
"Bar": {"type": "string"},
318+
},
319+
"definitions": {
320+
"XYZ": {
321+
"type": "object",
322+
"additionalProperties": False,
323+
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
324+
}
325+
},
326+
"primaryIdentifier": ["/properties/Foo"],
327+
"readOnlyProperties": ["/properties/Foo"],
328+
"createOnlyProperties": ["/properties/Foo"],
329+
"conditionalCreateOnlyProperties": ["/properties/Bar"],
330+
}
331+
result = load_resource_spec(json_s(schema))
332+
assert result == schema
333+
334+
335+
def test_load_resource_spec_without_array_type_valid():
336+
schema = {
337+
"typeName": "AWS::FOO::BAR",
338+
"description": "test schema",
339+
"additionalProperties": False,
340+
"properties": {
341+
"foo": {
342+
"type": "array",
343+
"uniqueItems": False,
344+
"insertionOrder": False,
345+
"items": {"$ref": "#/definitions/XYZ"},
346+
},
347+
"bar": {"type": "string"},
348+
},
349+
"definitions": {
350+
"XYZ": {
351+
"type": "object",
352+
"additionalProperties": False,
353+
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
354+
}
355+
},
356+
"primaryIdentifier": ["/properties/foo"],
357+
"readOnlyProperties": ["/properties/foo"],
358+
"createOnlyProperties": ["/properties/foo"],
359+
"conditionalCreateOnlyProperties": ["/properties/bar"],
360+
}
361+
result = load_resource_spec(json_s(schema))
362+
assert result == schema
363+
364+
270365
def test_argparse_stdin_name():
271366
"""By default, pytest messes with stdin and stdout, which prevents me from
272367
writing a test to check we have the right magic name that argparse uses

0 commit comments

Comments
 (0)