@@ -601,6 +601,122 @@ def test_generate_docs_with_multiref_property(project, tmp_path_factory):
601601 assert read_me_stripped == read_me_target_stripped
602602
603603
604+ def test_when_array_property_has_items_then_generated_docs_should_use_specified_items_type (
605+ project , tmp_path_factory , session
606+ ):
607+ project .artifact_type = ARTIFACT_TYPE_HOOK
608+ project .schema = resource_json (
609+ __name__ ,
610+ "data/schema/hook/valid/valid_hook_configuration_with_array_items.json" ,
611+ )
612+ project .type_name = "TestOnly::Sample::Hook"
613+ # tmpdir conflicts with other tests, make a unique one
614+ project .root = tmp_path_factory .mktemp (
615+ "generate_docs_when_array_property_has_items"
616+ )
617+
618+ project .load_configuration_schema ()
619+
620+ mock_plugin = MagicMock (spec = ["generate" ])
621+ patch_session = patch ("rpdk.core.boto_helpers.Boto3Session" )
622+
623+ def get_test_schema ():
624+ return {
625+ "typeName" : "AWS::S3::Bucket" ,
626+ "description" : "test schema" ,
627+ "properties" : {"foo" : {"type" : "string" }},
628+ "primaryIdentifier" : ["/properties/foo" ],
629+ "additionalProperties" : False ,
630+ }
631+
632+ mock_cfn_client = MagicMock (spec = ["describe_type" ])
633+ with patch .object (project , "_plugin" , mock_plugin ), patch_session as mock_session :
634+ mock_cfn_client .describe_type .return_value = {
635+ "Schema" : json .dumps (get_test_schema ()),
636+ "Type" : "" ,
637+ "ProvisioningType" : "" ,
638+ }
639+ session .client .side_effect = [mock_cfn_client , MagicMock ()]
640+ mock_session .return_value = session
641+ project .generate ()
642+ project .generate_docs ()
643+ mock_plugin .generate .assert_called_once_with (project )
644+
645+ docs_dir = project .root / "docs"
646+ readme_file = project .root / "docs" / "README.md"
647+
648+ assert docs_dir .is_dir ()
649+ assert readme_file .is_file ()
650+ with patch .object (project , "_plugin" , mock_plugin ), patch_session as mock_session :
651+ session .client .side_effect = [mock_cfn_client , MagicMock ()]
652+ mock_session .return_value = session
653+ project .generate ()
654+ readme_contents = readme_file .read_text (encoding = "utf-8" ).strip ().replace ("\n " , " " )
655+ assert project .type_name in readme_contents
656+ assert (
657+ "exampleArrayProperty Example property of array type with items of string type. _Required_: No _Type_: List of String"
658+ in readme_contents
659+ )
660+
661+
662+ def test_when_array_property_has_no_items_then_generated_docs_should_default_to_map_items_type (
663+ project , tmp_path_factory , session
664+ ):
665+ project .artifact_type = ARTIFACT_TYPE_HOOK
666+ project .schema = resource_json (
667+ __name__ ,
668+ "data/schema/hook/valid/valid_hook_configuration_without_array_items.json" ,
669+ )
670+ project .type_name = "TestOnly::Sample::Hook"
671+ # tmpdir conflicts with other tests, make a unique one
672+ project .root = tmp_path_factory .mktemp (
673+ "generate_docs_when_array_property_has_no_items"
674+ )
675+
676+ project .load_configuration_schema ()
677+
678+ mock_plugin = MagicMock (spec = ["generate" ])
679+ patch_session = patch ("rpdk.core.boto_helpers.Boto3Session" )
680+
681+ def get_test_schema ():
682+ return {
683+ "typeName" : "AWS::S3::Bucket" ,
684+ "description" : "test schema" ,
685+ "properties" : {"foo" : {"type" : "string" }},
686+ "primaryIdentifier" : ["/properties/foo" ],
687+ "additionalProperties" : False ,
688+ }
689+
690+ mock_cfn_client = MagicMock (spec = ["describe_type" ])
691+ with patch .object (project , "_plugin" , mock_plugin ), patch_session as mock_session :
692+ mock_cfn_client .describe_type .return_value = {
693+ "Schema" : json .dumps (get_test_schema ()),
694+ "Type" : "" ,
695+ "ProvisioningType" : "" ,
696+ }
697+ session .client .side_effect = [mock_cfn_client , MagicMock ()]
698+ mock_session .return_value = session
699+ project .generate ()
700+ project .generate_docs ()
701+ mock_plugin .generate .assert_called_once_with (project )
702+
703+ docs_dir = project .root / "docs"
704+ readme_file = project .root / "docs" / "README.md"
705+
706+ assert docs_dir .is_dir ()
707+ assert readme_file .is_file ()
708+ with patch .object (project , "_plugin" , mock_plugin ), patch_session as mock_session :
709+ session .client .side_effect = [mock_cfn_client , MagicMock ()]
710+ mock_session .return_value = session
711+ project .generate ()
712+ readme_contents = readme_file .read_text (encoding = "utf-8" ).strip ().replace ("\n " , " " )
713+ assert project .type_name in readme_contents
714+ assert (
715+ "exampleArrayProperty Example property of array type without items (that is, an 'items` key at this same level). _Required_: No _Type_: List of Map"
716+ in readme_contents
717+ )
718+
719+
604720def test_generate_with_docs_invalid_property_type (project , tmp_path_factory ):
605721 project .schema = resource_json (
606722 __name__ , "data/schema/invalid/invalid_property_type_invalid.json"
0 commit comments