diff --git a/src/rpdk/core/data/schema/base.definition.schema.v1.json b/src/rpdk/core/data/schema/base.definition.schema.v1.json index b5b844dc..df2fcbd9 100644 --- a/src/rpdk/core/data/schema/base.definition.schema.v1.json +++ b/src/rpdk/core/data/schema/base.definition.schema.v1.json @@ -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" }, diff --git a/tests/test_data_loaders.py b/tests/test_data_loaders.py index 265514c4..20821904 100644 --- a/tests/test_data_loaders.py +++ b/tests/test_data_loaders.py @@ -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",