11use std:: ops:: Not ;
22
3- use darling:: { util:: IdentString , FromAttributes , Result } ;
3+ use darling:: { util:: IdentString , Error , FromAttributes , Result } ;
44use proc_macro2:: TokenStream ;
55use quote:: quote;
66use syn:: { parse_quote, ItemStruct , Path } ;
@@ -32,6 +32,15 @@ impl Container {
3232 }
3333
3434 let kubernetes_options = attributes. kubernetes_arguments . map ( Into :: into) ;
35+ let idents: ContainerIdents = item_struct. ident . into ( ) ;
36+
37+ // Validate K8s specific requirements
38+ // Ensure that the struct name includes the 'Spec' suffix.
39+ if kubernetes_options. is_some ( ) && !idents. original . as_str ( ) . ends_with ( "Spec" ) {
40+ return Err ( Error :: custom (
41+ "struct name needs to include the `Spec` suffix if Kubernetes features are enabled via `#[versioned(k8s())]`"
42+ ) . with_span ( & idents. original . span ( ) ) ) ;
43+ }
3544
3645 let options = ContainerOptions {
3746 skip_from : attributes
@@ -42,8 +51,6 @@ impl Container {
4251 kubernetes_options,
4352 } ;
4453
45- let idents: ContainerIdents = item_struct. ident . into ( ) ;
46-
4754 let common = CommonContainerData {
4855 original_attributes : item_struct. attrs ,
4956 options,
@@ -71,6 +78,15 @@ impl Container {
7178 }
7279
7380 let kubernetes_options = attributes. kubernetes_arguments . map ( Into :: into) ;
81+ let idents: ContainerIdents = item_struct. ident . into ( ) ;
82+
83+ // Validate K8s specific requirements
84+ // Ensure that the struct name includes the 'Spec' suffix.
85+ if kubernetes_options. is_some ( ) && !idents. original . as_str ( ) . ends_with ( "Spec" ) {
86+ return Err ( Error :: custom (
87+ "struct name needs to include the `Spec` suffix if Kubernetes features are enabled via `#[versioned(k8s())]`"
88+ ) . with_span ( & idents. original . span ( ) ) ) ;
89+ }
7490
7591 let options = ContainerOptions {
7692 skip_from : attributes
@@ -80,8 +96,6 @@ impl Container {
8096 kubernetes_options,
8197 } ;
8298
83- let idents: ContainerIdents = item_struct. ident . into ( ) ;
84-
8599 // Nested structs
86100 // We need to filter out the `versioned` attribute, because these are not directly processed
87101 // by darling, but instead by us (using darling). For this reason, darling won't remove the
0 commit comments