Skip to content

Commit

Permalink
Remove v3 & management.cattle.io APIs in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlawr authored and guangbochen committed Jun 15, 2021
1 parent 199b3b7 commit 10455bf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 76 deletions.
5 changes: 1 addition & 4 deletions pkg/genswagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
27 changes: 2 additions & 25 deletions pkg/genswagger/rest/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)).
Expand Down
37 changes: 0 additions & 37 deletions pkg/genswagger/rest/models.go

This file was deleted.

11 changes: 1 addition & 10 deletions scripts/generate-openapi
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 10455bf

Please sign in to comment.