@@ -201,26 +201,30 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {
201201 serverConfig .OpenAPIConfig .PostProcessSpec = func (swagger * spec.Swagger ) (* spec.Swagger , error ) {
202202 defs := swagger .Definitions
203203
204- // Check basic Application definition
204+ // Verify the presence of the base Application/ApplicationList definitions
205205 appDef , exists := defs ["com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Application" ]
206206 if ! exists {
207207 return swagger , fmt .Errorf ("Application definition not found" )
208208 }
209209
210- // Check basic ApplicationList definition
211210 listDef , exists := defs ["com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList" ]
212211 if ! exists {
213212 return swagger , fmt .Errorf ("ApplicationList definition not found" )
214213 }
215214
215+ // Iterate over all registered GVKs (e.g., Bucket, Database, etc.)
216216 for _ , gvk := range v1alpha1 .RegisteredGVKs {
217+ // This will be something like:
218+ // "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Bucket"
217219 resourceName := fmt .Sprintf ("com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.%s" , gvk .Kind )
220+
221+ // 1. Create a copy of the base Application definition for the new resource
218222 newDef , err := DeepCopySchema (& appDef )
219223 if err != nil {
220224 return nil , fmt .Errorf ("failed to deepcopy schema for %s: %w" , gvk .Kind , err )
221225 }
222226
223- // Fix Extensions for resource
227+ // 2. Update x-kubernetes-group-version-kind to match the new resource
224228 if newDef .Extensions == nil {
225229 newDef .Extensions = map [string ]interface {}{}
226230 }
@@ -231,17 +235,20 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {
231235 "kind" : gvk .Kind ,
232236 },
233237 }
238+
239+ // 3. Save the new resource definition under the correct name
234240 defs [resourceName ] = * newDef
235241 klog .V (6 ).Infof ("PostProcessSpec: Added OpenAPI definition for %s\n " , resourceName )
236242
237- // List resource
243+ // 4. Now handle the corresponding List type (e.g., BucketList).
244+ // We'll start by copying the ApplicationList definition.
238245 listResourceName := fmt .Sprintf ("com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.%sList" , gvk .Kind )
239246 newListDef , err := DeepCopySchema (& listDef )
240247 if err != nil {
241248 return nil , fmt .Errorf ("failed to deepcopy schema for %sList: %w" , gvk .Kind , err )
242249 }
243250
244- // Fix Extensions for List resource
251+ // 5. Update x-kubernetes-group-version-kind for the List definition
245252 if newListDef .Extensions == nil {
246253 newListDef .Extensions = map [string ]interface {}{}
247254 }
@@ -252,10 +259,22 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {
252259 "kind" : fmt .Sprintf ("%sList" , gvk .Kind ),
253260 },
254261 }
262+
263+ // 6. IMPORTANT: Fix the "items" reference so it points to the new resource
264+ // rather than to "Application".
265+ if itemsProp , found := newListDef .Properties ["items" ]; found {
266+ if itemsProp .Items != nil && itemsProp .Items .Schema != nil {
267+ itemsProp .Items .Schema .Ref = spec .MustCreateRef ("#/definitions/" + resourceName )
268+ newListDef .Properties ["items" ] = itemsProp
269+ }
270+ }
271+
272+ // 7. Finally, save the new List definition
255273 defs [listResourceName ] = * newListDef
256274 klog .V (6 ).Infof ("PostProcessSpec: Added OpenAPI definition for %s\n " , listResourceName )
257275 }
258276
277+ // Remove the original Application/ApplicationList from the definitions
259278 delete (defs , "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Application" )
260279 delete (defs , "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList" )
261280
0 commit comments