diff --git a/examples/crd_derive_schema.rs b/examples/crd_derive_schema.rs index 80336bf3f..4a69d29d1 100644 --- a/examples/crd_derive_schema.rs +++ b/examples/crd_derive_schema.rs @@ -89,8 +89,8 @@ pub struct FooSpec { set_listable: Vec, // Field with CEL validation #[serde(default)] - #[validated(rule="self != 'illegal'", message="string cannot be illegal")] - #[validated(rule="self != 'not legal'")] + #[validated(rule = "self != 'illegal'", message = "string cannot be illegal")] + #[validated(rule = "self != 'not legal'")] cel_validated: Option, } // https://kubernetes.io/docs/reference/using-api/server-side-apply/#merge-strategy diff --git a/kube-derive/src/custom_resource.rs b/kube-derive/src/custom_resource.rs index d16b1a1a0..b455e3c96 100644 --- a/kube-derive/src/custom_resource.rs +++ b/kube-derive/src/custom_resource.rs @@ -552,10 +552,7 @@ pub(crate) fn cel_validation(_: TokenStream, input: TokenStream) -> TokenStream Ok(di) => di, }; - if !ast - .attrs - .iter().any(|attr| attr.path().is_ident("derive")) - { + if !ast.attrs.iter().any(|attr| attr.path().is_ident("derive")) { return syn::Error::new( ast.ident.span(), r#"#[cel_validation] macro should be placed before the #[derive(JsonSchema)] macro"#, diff --git a/kube-derive/src/lib.rs b/kube-derive/src/lib.rs index 10cd42e6c..b29e4c88d 100644 --- a/kube-derive/src/lib.rs +++ b/kube-derive/src/lib.rs @@ -343,7 +343,10 @@ pub fn derive_custom_resource(input: proc_macro::TokenStream) -> proc_macro::Tok /// assert!(serde_json::to_string(&Struct::crd()).unwrap().contains(r#""rule":"self != ''""#)); /// ``` #[proc_macro_attribute] -pub fn cel_validation(args: proc_macro::TokenStream, input: proc_macro::TokenStream) -> proc_macro::TokenStream { +pub fn cel_validation( + args: proc_macro::TokenStream, + input: proc_macro::TokenStream, +) -> proc_macro::TokenStream { custom_resource::cel_validation(args.into(), input.into()).into() }