From 10455bfc99c78773c4044ccc35be70ae731f8e9f Mon Sep 17 00:00:00 2001 From: gitlawr Date: Wed, 9 Jun 2021 10:25:08 +0800 Subject: [PATCH] Remove v3 & management.cattle.io APIs in docs --- pkg/genswagger/main.go | 5 +--- pkg/genswagger/rest/definitions.go | 27 ++-------------------- pkg/genswagger/rest/models.go | 37 ------------------------------ scripts/generate-openapi | 11 +-------- 4 files changed, 4 insertions(+), 76 deletions(-) delete mode 100644 pkg/genswagger/rest/models.go diff --git a/pkg/genswagger/main.go b/pkg/genswagger/main.go index 02f4c5bf56..a4d37efcbc 100644 --- a/pkg/genswagger/main.go +++ b/pkg/genswagger/main.go @@ -53,9 +53,7 @@ func createConfig() *common.Config { }, }, GetDefinitions: func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { - m := v1beta1.GetOpenAPIDefinitions(ref) - rest.AddV3OpenAPIDefinitions(m, ref) - return m + return v1beta1.GetOpenAPIDefinitions(ref) }, GetDefinitionName: func(name string) (string, spec.Extensions) { @@ -65,7 +63,6 @@ func createConfig() *common.Config { name = strings.ReplaceAll(name, "k8s.io/apimachinery/pkg/apis/meta", "k8s.io") name = strings.ReplaceAll(name, "kubevirt.io/client-go/api", "kubevirt.io") name = strings.ReplaceAll(name, "kubevirt.io/containerized-data-importer/pkg/apis/core", "cdi.kubevirt.io") - name = strings.ReplaceAll(name, "github.com/rancher/rancher/pkg/apis/management.cattle.io", "management.cattle.io") name = strings.ReplaceAll(name, "/", ".") return name, nil diff --git a/pkg/genswagger/rest/definitions.go b/pkg/genswagger/rest/definitions.go index f7daee0c44..7d2a35ab27 100644 --- a/pkg/genswagger/rest/definitions.go +++ b/pkg/genswagger/rest/definitions.go @@ -7,7 +7,6 @@ import ( "strings" restful "github.com/emicklei/go-restful" - v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -59,15 +58,7 @@ func AggregatedAPIs() []*restful.WebService { AddGenericNamespacedResourceRoutes(virtv1API, vmGVR, &virtv1.VirtualMachine{}, "VirtualMachine", &virtv1.VirtualMachineList{}) AddGenericNamespacedResourceRoutes(virtv1API, migrationGVR, &virtv1.VirtualMachineInstanceMigration{}, "VirtualMachineInstanceMigration", &virtv1.VirtualMachineInstanceMigrationList{}) - // rancher - - rancherAPI := NewGroupWebService(v3.SchemeGroupVersion) - rancherV3API := NewGroupVersionWebService(v3.SchemeGroupVersion) - userGVR := schema.GroupVersionResource{Group: v3.SchemeGroupVersion.Group, Version: v3.SchemeGroupVersion.Version, Resource: "users"} - - AddGenericNonNamespacedResourceRoutes(rancherV3API, userGVR, &v3.User{}, "User", &v3.UserList{}) - - return []*restful.WebService{harvesterAPI, harvesterv1beta1API, cdiAPI, cdiv1beta1API, virtAPI, virtv1API, rancherAPI, rancherV3API, customV3API()} + return []*restful.WebService{harvesterAPI, harvesterv1beta1API, cdiAPI, cdiv1beta1API, virtAPI, virtv1API} } func NewGroupVersionWebService(gv schema.GroupVersion) *restful.WebService { @@ -85,6 +76,7 @@ func NewGroupVersionWebService(gv schema.GroupVersion) *restful.WebService { ) return ws } + func AddGenericNonNamespacedResourceRoutes(ws *restful.WebService, gvr schema.GroupVersionResource, objPointer runtime.Object, objKind string, objListPointer runtime.Object) { AddGenericResourceRoutes(ws, gvr, objPointer, objKind, objListPointer, false) } @@ -212,21 +204,6 @@ func NewGroupWebService(gv schema.GroupVersion) *restful.WebService { return ws } -func customV3API() *restful.WebService { - ws := new(restful.WebService).Path("/") - - ws.Route( - ws.POST("/v3-public/localProviders/local?action=login"). - Produces(mime.MIME_JSON). - Operation("localAuthLogin"). - To(Noop).Reads(&v3.BasicLogin{}).Writes(metav1.Status{}). - Doc("local auth login."). - Returns(http.StatusOK, "OK", metav1.Status{}). - Returns(http.StatusUnauthorized, "Unauthorized", ""), - ) - return ws -} - func addCollectionParams(builder *restful.RouteBuilder, ws *restful.WebService) *restful.RouteBuilder { return builder.Param(continueParam(ws)). Param(fieldSelectorParam(ws)). diff --git a/pkg/genswagger/rest/models.go b/pkg/genswagger/rest/models.go deleted file mode 100644 index 993ec8f2c2..0000000000 --- a/pkg/genswagger/rest/models.go +++ /dev/null @@ -1,37 +0,0 @@ -package rest - -import ( - spec "github.com/go-openapi/spec" - common "k8s.io/kube-openapi/pkg/common" -) - -func AddV3OpenAPIDefinitions(definitions map[string]common.OpenAPIDefinition, ref common.ReferenceCallback) { - definitions["github.com/rancher/rancher/pkg/apis/management.cattle.io/v3.BasicLogin"] = schemaManagementCattleIOV3BasicLoginResponse(ref) -} - -func schemaManagementCattleIOV3BasicLoginResponse(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "BasicLogin is a the input for local auth login action", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "username": { - SchemaProps: spec.SchemaProps{ - Description: "Username for the login.", - Type: []string{"string"}, - Format: "", - }, - }, - "password": { - SchemaProps: spec.SchemaProps{ - Description: "Password for the login.", - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - } -} diff --git a/scripts/generate-openapi b/scripts/generate-openapi index d64e54bfb4..b32d6247b7 100755 --- a/scripts/generate-openapi +++ b/scripts/generate-openapi @@ -5,19 +5,10 @@ set -e file=pkg/apis/harvesterhci.io/v1beta1/doc.go awk '/package v1beta1/ { print "// +k8s:openapi-gen=true"; print; next }1' $file > tmp && mv tmp $file; -# Add +k8s:openapi-gen=true to v3 resources -#files=$(ls -d vendor/github.com/rancher/rancher/pkg/apis/management.cattle.io/v3/*) -for file in vendor/github.com/rancher/rancher/pkg/apis/management.cattle.io/v3/*.go; do - awk '/type User/ { print "// +k8s:openapi-gen=true"; print; next }1' $file > tmp && mv tmp $file; -done - -GO111MODULE=auto openapi-gen --input-dirs k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/api/errors,github.com/openshift/api/operator/v1,kubevirt.io/client-go/api/v1,kubevirt.io/client-go/apis/snapshot/v1alpha1,kubevirt.io/containerized-data-importer/pkg/apis/core/v1beta1,kubevirt.io/containerized-data-importer/pkg/apis/core/v1alpha1,github.com/rancher/rancher/pkg/apis/management.cattle.io/v3,github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1 \ +GO111MODULE=auto openapi-gen --input-dirs k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/api/errors,github.com/openshift/api/operator/v1,kubevirt.io/client-go/api/v1,kubevirt.io/client-go/apis/snapshot/v1alpha1,kubevirt.io/containerized-data-importer/pkg/apis/core/v1beta1,kubevirt.io/containerized-data-importer/pkg/apis/core/v1alpha1,github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1 \ --output-package github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1 \ --go-header-file scripts/boilerplate.go.txt > scripts/known-api-rule-violations.txt -# cleanup +k8s:openapi-gen=true in vendor files. -git checkout -- vendor - # generate swagger.json go run pkg/genswagger/main.go