Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openapi spec for cozystack apps #571

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix openapi spec for cozystack apps
Signed-off-by: Andrei Kvapil <[email protected]>
kvaps committed Jan 13, 2025
commit f65f4c9cbca487af8377d8190660fc69389618dc
14 changes: 7 additions & 7 deletions pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
@@ -202,21 +202,21 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {
defs := swagger.Definitions

// Verify the presence of the base Application/ApplicationList definitions
appDef, exists := defs["com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Application"]
appDef, exists := defs["com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.Application"]
if !exists {
return swagger, fmt.Errorf("Application definition not found")
}

listDef, exists := defs["com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList"]
listDef, exists := defs["com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList"]
if !exists {
return swagger, fmt.Errorf("ApplicationList definition not found")
}

// Iterate over all registered GVKs (e.g., Bucket, Database, etc.)
for _, gvk := range v1alpha1.RegisteredGVKs {
// This will be something like:
// "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Bucket"
resourceName := fmt.Sprintf("com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.%s", gvk.Kind)
// "com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.Bucket"
resourceName := fmt.Sprintf("com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.%s", gvk.Kind)

// 1. Create a copy of the base Application definition for the new resource
newDef, err := DeepCopySchema(&appDef)
@@ -242,7 +242,7 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {

// 4. Now handle the corresponding List type (e.g., BucketList).
// We'll start by copying the ApplicationList definition.
listResourceName := fmt.Sprintf("com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.%sList", gvk.Kind)
listResourceName := fmt.Sprintf("com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.%sList", gvk.Kind)
newListDef, err := DeepCopySchema(&listDef)
if err != nil {
return nil, fmt.Errorf("failed to deepcopy schema for %sList: %w", gvk.Kind, err)
@@ -275,8 +275,8 @@ func (o *AppsServerOptions) Config() (*apiserver.Config, error) {
}

// Remove the original Application/ApplicationList from the definitions
delete(defs, "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.Application")
delete(defs, "com.github.aenix.io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList")
delete(defs, "com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.Application")
delete(defs, "com.github.aenix-io.cozystack.pkg.apis.apps.v1alpha1.ApplicationList")

swagger.Definitions = defs
return swagger, nil