From 2473d4b9c4ee836e645459328c18f043c32d1b8e Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Fri, 9 Feb 2024 19:01:26 -0800 Subject: [PATCH] Configure openapi v3 (#35) Signed-off-by: Tamal Saha --- pkg/cmds/server/start.go | 20 ++++++++++++++++---- pkg/registry/ui/backups/backupoverview.go | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/cmds/server/start.go b/pkg/cmds/server/start.go index d59eea59..4c2e1233 100644 --- a/pkg/cmds/server/start.go +++ b/pkg/cmds/server/start.go @@ -93,6 +93,11 @@ func (o *UIServerOptions) Config() (*apiserver.Config, error) { // Fixes https://github.com/Azure/AKS/issues/522 clientcmd.Fix(serverConfig.ClientConfig) + ignorePrefixes := []string{ + "/swaggerapi", + fmt.Sprintf("/apis/%s/%s", uiv1alpha1.SchemeGroupVersion, uiv1alpha1.ResourceBackupOverviews), + } + serverConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig( ou.GetDefinitions( api.GetOpenAPIDefinitions, @@ -101,10 +106,17 @@ func (o *UIServerOptions) Config() (*apiserver.Config, error) { openapi.NewDefinitionNamer(apiserver.Scheme)) serverConfig.OpenAPIConfig.Info.Title = "stash-ui-server" serverConfig.OpenAPIConfig.Info.Version = v.Version.Version - serverConfig.OpenAPIConfig.IgnorePrefixes = []string{ - "/swaggerapi", - fmt.Sprintf("/apis/%s/%s", uiv1alpha1.SchemeGroupVersion, uiv1alpha1.ResourceBackupOverviews), - } + serverConfig.OpenAPIConfig.IgnorePrefixes = ignorePrefixes + + serverConfig.OpenAPIV3Config = genericapiserver.DefaultOpenAPIV3Config( + ou.GetDefinitions( + api.GetOpenAPIDefinitions, + uiv1alpha1.GetOpenAPIDefinitions, + ), + openapi.NewDefinitionNamer(apiserver.Scheme)) + serverConfig.OpenAPIV3Config.Info.Title = "stash-ui-server" + serverConfig.OpenAPIV3Config.Info.Version = v.Version.Version + serverConfig.OpenAPIV3Config.IgnorePrefixes = ignorePrefixes if err := o.ExtraOptions.ApplyTo(serverConfig.ClientConfig); err != nil { return nil, err diff --git a/pkg/registry/ui/backups/backupoverview.go b/pkg/registry/ui/backups/backupoverview.go index 204430f9..a733714b 100644 --- a/pkg/registry/ui/backups/backupoverview.go +++ b/pkg/registry/ui/backups/backupoverview.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strings" "time" stashapi "stash.appscode.dev/apimachinery/apis/stash" @@ -56,6 +57,7 @@ var ( _ rest.Storage = &BackupOverviewStorage{} _ rest.Getter = &BackupOverviewStorage{} _ rest.Lister = &BackupOverviewStorage{} + _ rest.SingularNameProvider = &BackupOverviewStorage{} ) func NewBackupOverviewStorage(kc client.Client, a authorizer.Authorizer) *BackupOverviewStorage { @@ -77,6 +79,10 @@ func (r *BackupOverviewStorage) GroupVersionKind(_ schema.GroupVersion) schema.G return uiapi.SchemeGroupVersion.WithKind(uiapi.ResourceKindBackupOverview) } +func (r *BackupOverviewStorage) GetSingularName() string { + return strings.ToLower(uiapi.ResourceKindBackupOverview) +} + func (r *BackupOverviewStorage) NamespaceScoped() bool { return true }