Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/rpdk/core/data/schema/base.definition.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@
"AttributeList"
]
},
"relationshipRef": {
"$comment": "The relationshipRef relate a property in the resource to that in another resource",
"type": "object",
"properties": {
"typeName": {
"$comment": "Name of the related resource",
"type": "string",
"pattern": "^[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}$"
},
"propertyPath": {
"$comment": "Path of the property in the related resource schema",
"type": "string",
"pattern": "^(\/properties\/)[A-Za-z0-9]*$"
},
"publisherId": {
"$comment": "Id of the related third party resource publisher",
"type": "string",
"pattern": "[0-9a-zA-Z]{12,40}"
},
"majorVersion": {
"$comment": "Major version of the related resource",
"type": "integer",
"minimum": 1,
"maximum": 10000
}
},
"required": [
"typeName",
"propertyPath"
],
"additionalProperties": false
},
"$ref": {
"$ref": "http://json-schema.org/draft-07/schema#/properties/$ref"
},
Expand Down
84 changes: 84 additions & 0 deletions tests/test_data_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,90 @@ def test_load_resource_spec_without_array_type_valid():
assert result == schema


def test_load_resource_spec_with_relationship_valid():
schema = {
"typeName": "AWS::FOO::BAR",
"description": "test schema",
"additionalProperties": False,
"properties": {
"foo": {
"type": "string",
"relationshipRef": {
"typeName": "ABC::DEF::GHI",
"propertyPath": "/properties/id",
},
},
"bar": {"type": "string"},
},
"definitions": {
"XYZ": {
"type": "object",
"additionalProperties": False,
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
}
},
"primaryIdentifier": ["/properties/foo"],
"readOnlyProperties": ["/properties/foo"],
"createOnlyProperties": ["/properties/foo"],
"conditionalCreateOnlyProperties": ["/properties/bar"],
}
result = load_resource_spec(json_s(schema))
assert result == schema


def test_load_resource_spec_with_relationship_invalid():
schema = {
"typeName": "AWS::FOO::BAR",
"description": "test schema",
"additionalProperties": False,
"properties": {
"foo": {"type": "object", "relationshipRef": {"typeName": "ABC::DEF::GHI"}},
"bar": {"type": "string"},
},
"definitions": {
"XYZ": {
"type": "object",
"additionalProperties": False,
"properties": {"Value": {"type": "string"}, "Key": {"type": "string"}},
}
},
"primaryIdentifier": ["/properties/foo"],
"readOnlyProperties": ["/properties/foo"],
"createOnlyProperties": ["/properties/foo"],
"conditionalCreateOnlyProperties": ["/properties/bar"],
}
with pytest.raises(SpecValidationError) as excinfo:
load_resource_spec(json_s(schema))

assert "Failed validating" in str(excinfo.value)


def test_load_resource_spec_with_relationship_invalid_pattern():
schema = {
"typeName": "AWS::FOO::BAR",
"description": "test schema",
"additionalProperties": False,
"properties": {
"foo": {
"type": "string",
"relationshipRef": {
"typeName": "string",
"propertyPath": "string",
},
},
"bar": {"type": "string"},
},
"primaryIdentifier": ["/properties/foo"],
"readOnlyProperties": ["/properties/foo"],
"createOnlyProperties": ["/properties/foo"],
"conditionalCreateOnlyProperties": ["/properties/bar"],
}
with pytest.raises(SpecValidationError) as excinfo:
load_resource_spec(json_s(schema))

assert "does not match '^[a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}" in str(excinfo.value)


def test_load_hook_spec_properties_key_is_invalid():
schema = {
"typeName": "AWS::FOO::BAR",
Expand Down