cloudformation-cli icon indicating copy to clipboard operation
cloudformation-cli copied to clipboard

841 Validate properties are defined on cfn validate

Open mgentry612 opened this issue 2 years ago • 1 comments

Issue #, if available: 841

Description of changes: This PR is not ready for production - it makes several of the current test cases fail. I wanted to start a conversation about whether all of this validation is needed before I considered modifying current test cases. The main reason I made this PR was to introduce myself to the codebase. I realize this PR may or may not be helpful to your team. If you find that this PR is heading in the right direction, please provide feedback. If you're not interested in adding this functionality, no problem, it was fun diving in.

This PR implements validation for the top level of properties in the resource schema. For the following resource schema keys, a validation function ensures that properties at the top level of the "property" object are defined. "readOnlyProperties", "createOnlyProperties", "primaryIdentifier", "required", "additionalIdentifiers", "deprecatedProperties", "writeOnlyProperties",

The following assumptions are made in these changes, please confirm:

  • Properties are case sensitive
  • additionalIdentifiers, when defined, are always two dimensional arrays.

These changes handle examples like this: "createOnlyProperties": [ "/properties/Name" ]

but not nested properties like this, see below section about traversing the json structure: "createOnlyProperties": [ "/properties/obj1/obj2/str1" ]

As mentioned above, this PR omits nested properties. I started diving into nested properties but I decided I would need discuss the requirements before doing any more work. There were several complexities which I had questions about including the array data type and circular references. If you think it would be helpful to show you what I have so far for this on another branch, let me know and I'll share.

I've included several new test cases which run successfully only in isolation at this time. pytest --cov="rpdk.core" --doctest-modules --random-order-bucket="parent" "tests/test_data_loaders.py" -k test_load_resource_spec_property_not_defined --pyargs "rpdk.core" --verbose

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

mgentry612 avatar Jul 09 '22 20:07 mgentry612

To get all the validations included and keep them up to date over time is not a trivial task. May I suggest you give https://github.com/aws-cloudformation/resource-schema-guard-rail a try and see if it helps solve your problems? In the medium to long term I believe integrating guard rail into the cli is the way to go to keep the validations consistent.

mircealam avatar Oct 09 '23 18:10 mircealam