11//! Common types shared across CRDs
22
3- use std:: collections:: HashMap ;
3+ use std:: { borrow :: Cow , collections:: HashMap } ;
44
5- use schemars:: JsonSchema ;
5+ use schemars:: { JsonSchema , Schema , SchemaGenerator , json_schema } ;
66use serde:: { Deserialize , Serialize } ;
77
88pub use self :: { replica:: * , restore:: * } ;
@@ -52,7 +52,7 @@ pub struct SecretKeySelector {
5252 pub key : String ,
5353}
5454
55- #[ derive( Debug , Clone , Deserialize , Serialize , JsonSchema ) ]
55+ #[ derive( Debug , Clone , Deserialize , Serialize ) ]
5656#[ serde( untagged) ]
5757pub enum HeaderValue {
5858 Plain ( String ) ,
@@ -61,3 +61,36 @@ pub enum HeaderValue {
6161 secret_key_ref : SecretKeySelector ,
6262 } ,
6363}
64+
65+ impl JsonSchema for HeaderValue {
66+ fn inline_schema ( ) -> bool {
67+ true
68+ }
69+
70+ fn schema_name ( ) -> Cow < ' static , str > {
71+ "HeaderValue" . into ( )
72+ }
73+
74+ fn json_schema ( _generator : & mut SchemaGenerator ) -> Schema {
75+ // Kubernetes structural schemas forbid `type` inside `anyOf` items,
76+ // so we emit the branches without top-level `type`.
77+ json_schema ! ( {
78+ "anyOf" : [
79+ { } ,
80+ {
81+ "required" : [ "secretKeyRef" ] ,
82+ "properties" : {
83+ "secretKeyRef" : {
84+ "type" : "object" ,
85+ "properties" : {
86+ "name" : { "type" : "string" } ,
87+ "key" : { "type" : "string" }
88+ } ,
89+ "required" : [ "name" , "key" ]
90+ }
91+ }
92+ }
93+ ]
94+ } )
95+ }
96+ }
0 commit comments