@@ -5,6 +5,8 @@ use schemars::JsonSchema;
55use serde:: { Deserialize , Serialize } ;
66use serde_json:: json;
77
8+ // Enum definitions
9+
810/// A very simple enum with empty variants
911#[ derive( Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
1012enum NormalEnum {
@@ -18,6 +20,13 @@ enum NormalEnum {
1820 D ,
1921}
2022
23+ /// A complex enum with unit and struct variants
24+ #[ derive( Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
25+ enum ComplexEnum {
26+ Normal ( NormalEnum ) ,
27+ Hardcore { hard : String , core : NormalEnum } ,
28+ }
29+
2130/// An untagged enum with a nested enum inside
2231#[ derive( Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
2332#[ serde( untagged) ]
@@ -37,6 +46,8 @@ struct FlattenedUntaggedEnum {
3746 inner : UntaggedEnum ,
3847}
3948
49+ // CRD definitions
50+
4051#[ derive( CustomResource , Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
4152#[ kube( group = "clux.dev" , version = "v1" , kind = "NormalEnumTest" ) ]
4253struct NormalEnumTestSpec {
@@ -49,6 +60,18 @@ struct OptionalEnumTestSpec {
4960 foo : Option < NormalEnum > ,
5061}
5162
63+ #[ derive( CustomResource , Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
64+ #[ kube( group = "clux.dev" , version = "v1" , kind = "ComplexEnumTest" ) ]
65+ struct ComplexEnumTestSpec {
66+ foo : ComplexEnum ,
67+ }
68+
69+ #[ derive( CustomResource , Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
70+ #[ kube( group = "clux.dev" , version = "v1" , kind = "OptionalComplexEnumTest" ) ]
71+ struct OptionalComplexEnumTestSpec {
72+ foo : Option < ComplexEnum > ,
73+ }
74+
5275#[ derive( CustomResource , Serialize , Deserialize , Debug , Clone , JsonSchema ) ]
5376#[ kube( group = "clux.dev" , version = "v1" , kind = "UntaggedEnumTest" ) ]
5477struct UntaggedEnumTestSpec {
@@ -75,6 +98,13 @@ fn print_crds() {
7598 println ! ( "---" ) ;
7699 println ! ( "{}" , serde_yaml:: to_string( & OptionalEnumTest :: crd( ) ) . unwrap( ) ) ;
77100 println ! ( "---" ) ;
101+ println ! ( "{}" , serde_yaml:: to_string( & ComplexEnumTest :: crd( ) ) . unwrap( ) ) ;
102+ println ! ( "---" ) ;
103+ println ! (
104+ "{}" ,
105+ serde_yaml:: to_string( & OptionalComplexEnumTest :: crd( ) ) . unwrap( )
106+ ) ;
107+ println ! ( "---" ) ;
78108 println ! ( "{}" , serde_yaml:: to_string( & UntaggedEnumTest :: crd( ) ) . unwrap( ) ) ;
79109 println ! ( "---" ) ;
80110 println ! (
@@ -218,6 +248,18 @@ fn optional_enum() {
218248 ) ;
219249}
220250
251+
252+ #[ test]
253+ fn complex_enum ( ) {
254+ assert_json_eq ! ( ComplexEnumTest :: crd( ) , json!( 42 ) ) ;
255+ }
256+
257+
258+ #[ test]
259+ fn optional_complex_enum ( ) {
260+ assert_json_eq ! ( OptionalComplexEnumTest :: crd( ) , json!( 42 ) ) ;
261+ }
262+
221263#[ test]
222264fn untagged_enum ( ) {
223265 assert_json_eq ! (
0 commit comments