@@ -841,5 +841,56 @@ public void DeserializeWithJsonPropertyName()
841
841
var ver = result . Spec . Versions [ 0 ] ;
842
842
Assert . Equal ( true , ver ? . Schema ? . OpenAPIV3Schema ? . XKubernetesIntOrString ) ;
843
843
}
844
+
845
+ #pragma warning disable CA1812 // Class is used for YAML deserialization tests
846
+ [ KubernetesEntity ( Group = KubeGroup , Kind = KubeKind , ApiVersion = KubeApiVersion , PluralName = KubePluralName ) ]
847
+ private sealed class V1AlphaFoo : IKubernetesObject < V1ObjectMeta > , ISpec < Dictionary < string , object > >
848
+ {
849
+ public const string KubeApiVersion = "v1alpha" ;
850
+ public const string KubeKind = "foo" ;
851
+ public const string KubeGroup = "foo.bar" ;
852
+ public const string KubePluralName = "foos" ;
853
+
854
+ public string ApiVersion { get ; set ; }
855
+ public string Kind { get ; set ; }
856
+ public V1ObjectMeta Metadata { get ; set ; }
857
+ public Dictionary < string , object > Spec { get ; set ; }
858
+
859
+ public V1AlphaFoo ( )
860
+ {
861
+ Metadata = new V1ObjectMeta ( ) ;
862
+ Spec = new Dictionary < string , object > ( ) ;
863
+ }
864
+ }
865
+ #pragma warning restore CA1812 // Class is used for YAML deserialization tests
866
+
867
+ [ Fact ]
868
+ public void LoadAllFromStringWithTypeMapGenericCRD ( )
869
+ {
870
+ var content = @"apiVersion: foo.bar/v1alpha
871
+ kind: Foo
872
+ metadata:
873
+ name: foo
874
+ namespace: ns
875
+ spec:
876
+ bool: false
877
+ byte: 123
878
+ float: 12.0
879
+ " ;
880
+
881
+ var objs = KubernetesYaml . LoadAllFromString ( content , new Dictionary < string , Type >
882
+ {
883
+ { $ "{ V1AlphaFoo . KubeGroup } /{ V1AlphaFoo . KubeApiVersion } /Foo", typeof ( V1AlphaFoo ) } ,
884
+ } ) ;
885
+ Assert . Single ( objs ) ;
886
+ var v1AlphaFoo = Assert . IsType < V1AlphaFoo > ( objs [ 0 ] ) ;
887
+ Assert . Equal ( "foo" , v1AlphaFoo . Metadata . Name ) ;
888
+ Assert . Equal ( "ns" , v1AlphaFoo . Metadata . NamespaceProperty ) ;
889
+ Assert . Equal ( 3 , v1AlphaFoo . Spec . Count ) ;
890
+ Assert . False ( Assert . IsType < bool > ( v1AlphaFoo . Spec [ "bool" ] ) ) ;
891
+ Assert . Equal ( 123 , Assert . IsType < byte > ( v1AlphaFoo . Spec [ "byte" ] ) ) ;
892
+ Assert . Equal ( 12.0 , Assert . IsType < float > ( v1AlphaFoo . Spec [ "float" ] ) , 3 ) ;
893
+ Assert . Equal ( content . Replace ( "\r \n " , "\n " ) , KubernetesYaml . SerializeAll ( objs ) . Replace ( "\r \n " , "\n " ) ) ;
894
+ }
844
895
}
845
896
}
0 commit comments