Skip to content

Commit

Permalink
add relationshipRefs into the schema for validation (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
SwaySway authored May 23, 2024
1 parent 09d60db commit 4a8d9a0
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
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

0 comments on commit 4a8d9a0

Please sign in to comment.