@@ -729,6 +729,230 @@ func TestRemoveResponseIfHiddenForEnv(t *testing.T) {
729729	}
730730}
731731
732+ func  TestApplyOnSchemas (t  * testing.T ) {
733+ 	tests  :=  []struct  {
734+ 		name       string 
735+ 		schemas    openapi3.Schemas 
736+ 		targetEnv  string 
737+ 		expected   openapi3.Schemas 
738+ 	}{
739+ 		{
740+ 			name : "Remove schema hidden for target environment" ,
741+ 			schemas : openapi3.Schemas {
742+ 				"schema1" : {
743+ 					Extensions : map [string ]any {
744+ 						hiddenEnvsExtension : map [string ]any {
745+ 							"envs" : "prod" ,
746+ 						},
747+ 					},
748+ 				},
749+ 				"schema2" : {
750+ 					Extensions : map [string ]any {
751+ 						hiddenEnvsExtension : map [string ]any {
752+ 							"envs" : "dev" ,
753+ 						},
754+ 					},
755+ 				},
756+ 			},
757+ 			targetEnv : "prod" ,
758+ 			expected : openapi3.Schemas {
759+ 				"schema2" : {
760+ 					Extensions : map [string ]any {},
761+ 				},
762+ 			},
763+ 		},
764+ 		{
765+ 			name : "Remove properties hidden for target environment" ,
766+ 			schemas : openapi3.Schemas {
767+ 				"schema1" : {
768+ 					Value : & openapi3.Schema {
769+ 						Properties : map [string ]* openapi3.SchemaRef {
770+ 							"property1" : {
771+ 								Extensions : map [string ]any {
772+ 									hiddenEnvsExtension : map [string ]any {
773+ 										"envs" : "prod" ,
774+ 									},
775+ 								},
776+ 							},
777+ 							"property2" : {
778+ 								Extensions : map [string ]any {
779+ 									hiddenEnvsExtension : map [string ]any {
780+ 										"envs" : "dev" ,
781+ 									},
782+ 								},
783+ 							},
784+ 						},
785+ 					},
786+ 				},
787+ 			},
788+ 			targetEnv : "prod" ,
789+ 			expected : openapi3.Schemas {
790+ 				"schema1" : {
791+ 					Value : & openapi3.Schema {
792+ 						Properties : map [string ]* openapi3.SchemaRef {
793+ 							"property2" : {
794+ 								Extensions : map [string ]any {},
795+ 							},
796+ 						},
797+ 					},
798+ 				},
799+ 			},
800+ 		},
801+ 		{
802+ 			name : "Remove properties of properties hidden for target environment" ,
803+ 			schemas : openapi3.Schemas {
804+ 				"schema1" : {
805+ 					Value : & openapi3.Schema {
806+ 						Properties : map [string ]* openapi3.SchemaRef {
807+ 							"property1" : {
808+ 								Value : & openapi3.Schema {
809+ 									Properties : map [string ]* openapi3.SchemaRef {
810+ 										"subProperty1" : {
811+ 											Extensions : map [string ]any {
812+ 												hiddenEnvsExtension : map [string ]any {
813+ 													"envs" : "prod" ,
814+ 												},
815+ 											},
816+ 										},
817+ 										"subProperty2" : {
818+ 											Extensions : map [string ]any {
819+ 												hiddenEnvsExtension : map [string ]any {
820+ 													"envs" : "dev" ,
821+ 												},
822+ 											},
823+ 										},
824+ 									},
825+ 								},
826+ 							},
827+ 						},
828+ 					},
829+ 				},
830+ 			},
831+ 			targetEnv : "prod" ,
832+ 			expected : openapi3.Schemas {
833+ 				"schema1" : {
834+ 					Value : & openapi3.Schema {
835+ 						Properties : map [string ]* openapi3.SchemaRef {
836+ 							"property1" : {
837+ 								Value : & openapi3.Schema {
838+ 									Properties : map [string ]* openapi3.SchemaRef {
839+ 										"subProperty2" : {
840+ 											Extensions : map [string ]any {},
841+ 										},
842+ 									},
843+ 								},
844+ 							},
845+ 						},
846+ 					},
847+ 				},
848+ 			},
849+ 		},
850+ 		{
851+ 			name : "Retain schemas and properties not hidden for target environment" ,
852+ 			schemas : openapi3.Schemas {
853+ 				"schema1" : {
854+ 					Extensions : map [string ]any {
855+ 						hiddenEnvsExtension : map [string ]any {
856+ 							"envs" : "dev" ,
857+ 						},
858+ 					},
859+ 				},
860+ 				"schema2" : {
861+ 					Value : & openapi3.Schema {
862+ 						Properties : map [string ]* openapi3.SchemaRef {
863+ 							"property1" : {
864+ 								Extensions : map [string ]any {
865+ 									hiddenEnvsExtension : map [string ]any {
866+ 										"envs" : "dev" ,
867+ 									},
868+ 								},
869+ 							},
870+ 							"property2" : {
871+ 								Extensions : map [string ]any {},
872+ 							},
873+ 						},
874+ 					},
875+ 				},
876+ 			},
877+ 			targetEnv : "prod" ,
878+ 			expected : openapi3.Schemas {
879+ 				"schema1" : {
880+ 					Extensions : map [string ]any {},
881+ 				},
882+ 				"schema2" : {
883+ 					Value : & openapi3.Schema {
884+ 						Properties : map [string ]* openapi3.SchemaRef {
885+ 							"property1" : {
886+ 								Extensions : map [string ]any {},
887+ 							},
888+ 							"property2" : {
889+ 								Extensions : map [string ]any {},
890+ 							},
891+ 						},
892+ 					},
893+ 				},
894+ 			},
895+ 		},
896+ 		{
897+ 			name : "Remove hidden environment extension from final OAS" ,
898+ 			schemas : openapi3.Schemas {
899+ 				"schema1" : {
900+ 					Extensions : map [string ]any {
901+ 						hiddenEnvsExtension : map [string ]any {
902+ 							"envs" : "prod" ,
903+ 						},
904+ 					},
905+ 				},
906+ 				"schema2" : {
907+ 					Value : & openapi3.Schema {
908+ 						Properties : map [string ]* openapi3.SchemaRef {
909+ 							"property1" : {
910+ 								Extensions : map [string ]any {
911+ 									hiddenEnvsExtension : map [string ]any {
912+ 										"envs" : "prod" ,
913+ 									},
914+ 								},
915+ 							},
916+ 							"property2" : {
917+ 								Extensions : map [string ]any {},
918+ 							},
919+ 						},
920+ 					},
921+ 				},
922+ 			},
923+ 			targetEnv : "dev" ,
924+ 			expected : openapi3.Schemas {
925+ 				"schema1" : {
926+ 					Extensions : map [string ]any {},
927+ 				},
928+ 				"schema2" : {
929+ 					Value : & openapi3.Schema {
930+ 						Properties : map [string ]* openapi3.SchemaRef {
931+ 							"property1" : {
932+ 								Extensions : map [string ]any {},
933+ 							},
934+ 							"property2" : {
935+ 								Extensions : map [string ]any {},
936+ 							},
937+ 						},
938+ 					},
939+ 				},
940+ 			},
941+ 		},
942+ 	}
943+ 
944+ 	for  _ , tt  :=  range  tests  {
945+ 		t .Run (tt .name , func (t  * testing.T ) {
946+ 			filter  :=  HiddenEnvsFilter {
947+ 				metadata : & Metadata {targetEnv : tt .targetEnv },
948+ 			}
949+ 			err  :=  filter .applyOnSchemas (tt .schemas )
950+ 			require .NoError (t , err )
951+ 			assert .Equal (t , tt .expected , tt .schemas )
952+ 		})
953+ 	}
954+ }
955+ 
732956func  TestApply (t  * testing.T ) {
733957	metadata  :=  & Metadata {
734958		targetEnv : "prod" ,
0 commit comments