1
1
use std:: ops:: Not ;
2
2
3
- use darling:: { util:: IdentString , FromAttributes , Result } ;
3
+ use darling:: { util:: IdentString , Error , FromAttributes , Result } ;
4
4
use proc_macro2:: TokenStream ;
5
5
use quote:: quote;
6
6
use syn:: { parse_quote, ItemStruct , Path } ;
@@ -32,6 +32,15 @@ impl Container {
32
32
}
33
33
34
34
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
+ }
35
44
36
45
let options = ContainerOptions {
37
46
skip_from : attributes
@@ -42,8 +51,6 @@ impl Container {
42
51
kubernetes_options,
43
52
} ;
44
53
45
- let idents: ContainerIdents = item_struct. ident . into ( ) ;
46
-
47
54
let common = CommonContainerData {
48
55
original_attributes : item_struct. attrs ,
49
56
options,
@@ -71,6 +78,15 @@ impl Container {
71
78
}
72
79
73
80
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
+ }
74
90
75
91
let options = ContainerOptions {
76
92
skip_from : attributes
@@ -80,8 +96,6 @@ impl Container {
80
96
kubernetes_options,
81
97
} ;
82
98
83
- let idents: ContainerIdents = item_struct. ident . into ( ) ;
84
-
85
99
// Nested structs
86
100
// We need to filter out the `versioned` attribute, because these are not directly processed
87
101
// by darling, but instead by us (using darling). For this reason, darling won't remove the
0 commit comments