@@ -51,6 +51,70 @@ func TestGroupMultiPrefix(t *testing.T) {
51
51
assert .Equal (t , http .StatusNoContent , resp .Result ().StatusCode )
52
52
}
53
53
54
+ func TestGroupConvenienceEquivalency (t * testing.T ) {
55
+ _ , api := humatest .New (t )
56
+
57
+ // Register a normal route via convenience function.
58
+ huma .Get (api , "/v1/users" , func (ctx context.Context , input * struct {}) (* struct {}, error ) {
59
+ return nil , nil
60
+ })
61
+
62
+ // Upgrade to groups and expect the same behavior.
63
+ grp2 := huma .NewGroup (api , "/v2" )
64
+
65
+ huma .Get (grp2 , "/users" , func (ctx context.Context , input * struct {}) (* struct {}, error ) {
66
+ return nil , nil
67
+ })
68
+
69
+ // Ensure convenience overrides still work.
70
+ grp3 := huma .NewGroup (api , "/v3" )
71
+ huma .Get (grp3 , "/users" , func (ctx context.Context , input * struct {}) (* struct {}, error ) {
72
+ return nil , nil
73
+ }, func (o * huma.Operation ) {
74
+ o .OperationID = "custom-id"
75
+ o .Summary = "Custom summary"
76
+ })
77
+
78
+ // Ensure group overrides still work.
79
+ grp4 := huma .NewGroup (api , "/v4" )
80
+ grp4 .UseModifier (func (op * huma.Operation , next func (* huma.Operation )) {
81
+ op .OperationID = "custom-id"
82
+ op .Summary = "Custom summary"
83
+ next (op )
84
+ })
85
+ huma .Get (grp4 , "/users" , func (ctx context.Context , input * struct {}) (* struct {}, error ) {
86
+ return nil , nil
87
+ })
88
+
89
+ // Groups of groups should continue to work as well, including both groups in
90
+ // the generated ID/summary.
91
+ grp5 := huma .NewGroup (api , "/v5" )
92
+ grp6 := huma .NewGroup (grp5 , "/users" )
93
+ huma .Get (grp6 , "/" , func (ctx context.Context , input * struct {}) (* struct {}, error ) {
94
+ return nil , nil
95
+ })
96
+
97
+ oapi := api .OpenAPI ()
98
+
99
+ assert .NotNil (t , oapi .Paths ["/v1/users" ])
100
+ assert .NotNil (t , oapi .Paths ["/v2/users" ])
101
+ assert .NotNil (t , oapi .Paths ["/v3/users" ])
102
+ assert .NotNil (t , oapi .Paths ["/v4/users" ])
103
+ assert .NotNil (t , oapi .Paths ["/v5/users/" ])
104
+
105
+ assert .Equal (t , "get-v1-users" , oapi .Paths ["/v1/users" ].Get .OperationID )
106
+ assert .Equal (t , "get-v2-users" , oapi .Paths ["/v2/users" ].Get .OperationID )
107
+ assert .Equal (t , "custom-id" , oapi .Paths ["/v3/users" ].Get .OperationID )
108
+ assert .Equal (t , "custom-id" , oapi .Paths ["/v4/users" ].Get .OperationID )
109
+ assert .Equal (t , "get-v5-users" , oapi .Paths ["/v5/users/" ].Get .OperationID )
110
+
111
+ assert .Equal (t , "Get v1 users" , oapi .Paths ["/v1/users" ].Get .Summary )
112
+ assert .Equal (t , "Get v2 users" , oapi .Paths ["/v2/users" ].Get .Summary )
113
+ assert .Equal (t , "Custom summary" , oapi .Paths ["/v3/users" ].Get .Summary )
114
+ assert .Equal (t , "Custom summary" , oapi .Paths ["/v4/users" ].Get .Summary )
115
+ assert .Equal (t , "Get v5 users" , oapi .Paths ["/v5/users/" ].Get .Summary )
116
+ }
117
+
54
118
func TestGroupCustomizations (t * testing.T ) {
55
119
_ , api := humatest .New (t )
56
120
0 commit comments