Skip to content

Commit 4a8d9a0

Browse files
authored
add relationshipRefs into the schema for validation (#1071)
1 parent 09d60db commit 4a8d9a0

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@
7070
"AttributeList"
7171
]
7272
},
73+
"relationshipRef": {
74+
"$comment": "The relationshipRef relate a property in the resource to that in another resource",
75+
"type": "object",
76+
"properties": {
77+
"typeName": {
78+
"$comment": "Name of the related resource",
79+
"type": "string",
80+
"pattern": "^[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}$"
81+
},
82+
"propertyPath": {
83+
"$comment": "Path of the property in the related resource schema",
84+
"type": "string",
85+
"pattern": "^(\/properties\/)[A-Za-z0-9]*$"
86+
},
87+
"publisherId": {
88+
"$comment": "Id of the related third party resource publisher",
89+
"type": "string",
90+
"pattern": "[0-9a-zA-Z]{12,40}"
91+
},
92+
"majorVersion": {
93+
"$comment": "Major version of the related resource",
94+
"type": "integer",
95+
"minimum": 1,
96+
"maximum": 10000
97+
}
98+
},
99+
"required": [
100+
"typeName",
101+
"propertyPath"
102+
],
103+
"additionalProperties": false
104+
},
73105
"$ref": {
74106
"$ref": "http://json-schema.org/draft-07/schema#/properties/$ref"
75107
},

tests/test_data_loaders.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,90 @@ def test_load_resource_spec_without_array_type_valid():
383383
assert result == schema
384384

385385

386+
def test_load_resource_spec_with_relationship_valid():
387+
schema = {
388+
"typeName": "AWS::FOO::BAR",
389+
"description": "test schema",
390+
"additionalProperties": False,
391+
"properties": {
392+
"foo": {
393+
"type": "string",
394+
"relationshipRef": {
395+
"typeName": "ABC::DEF::GHI",
396+
"propertyPath": "/properties/id",
397+
},
398+
},
399+
"bar": {"type": "string"},
400+
},
401+
"definitions": {
402+
"XYZ": {
403+
"type": "object",
404+
"additionalProperties": False,
405+
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
406+
}
407+
},
408+
"primaryIdentifier": ["/properties/foo"],
409+
"readOnlyProperties": ["/properties/foo"],
410+
"createOnlyProperties": ["/properties/foo"],
411+
"conditionalCreateOnlyProperties": ["/properties/bar"],
412+
}
413+
result = load_resource_spec(json_s(schema))
414+
assert result == schema
415+
416+
417+
def test_load_resource_spec_with_relationship_invalid():
418+
schema = {
419+
"typeName": "AWS::FOO::BAR",
420+
"description": "test schema",
421+
"additionalProperties": False,
422+
"properties": {
423+
"foo": {"type": "object", "relationshipRef": {"typeName": "ABC::DEF::GHI"}},
424+
"bar": {"type": "string"},
425+
},
426+
"definitions": {
427+
"XYZ": {
428+
"type": "object",
429+
"additionalProperties": False,
430+
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
431+
}
432+
},
433+
"primaryIdentifier": ["/properties/foo"],
434+
"readOnlyProperties": ["/properties/foo"],
435+
"createOnlyProperties": ["/properties/foo"],
436+
"conditionalCreateOnlyProperties": ["/properties/bar"],
437+
}
438+
with pytest.raises(SpecValidationError) as excinfo:
439+
load_resource_spec(json_s(schema))
440+
441+
assert "Failed validating" in str(excinfo.value)
442+
443+
444+
def test_load_resource_spec_with_relationship_invalid_pattern():
445+
schema = {
446+
"typeName": "AWS::FOO::BAR",
447+
"description": "test schema",
448+
"additionalProperties": False,
449+
"properties": {
450+
"foo": {
451+
"type": "string",
452+
"relationshipRef": {
453+
"typeName": "string",
454+
"propertyPath": "string",
455+
},
456+
},
457+
"bar": {"type": "string"},
458+
},
459+
"primaryIdentifier": ["/properties/foo"],
460+
"readOnlyProperties": ["/properties/foo"],
461+
"createOnlyProperties": ["/properties/foo"],
462+
"conditionalCreateOnlyProperties": ["/properties/bar"],
463+
}
464+
with pytest.raises(SpecValidationError) as excinfo:
465+
load_resource_spec(json_s(schema))
466+
467+
assert "does not match '^[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}" in str(excinfo.value)
468+
469+
386470
def test_load_hook_spec_properties_key_is_invalid():
387471
schema = {
388472
"typeName": "AWS::FOO::BAR",

0 commit comments

Comments
 (0)