Skip to content

Commit

Permalink
Generate swagger.json (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha authored Apr 9, 2018
1 parent f8d494b commit 89e0070
Show file tree
Hide file tree
Showing 22 changed files with 5,862 additions and 93 deletions.
5,064 changes: 5,064 additions & 0 deletions apis/swagger.json

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions hack/codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ for gv in "${apiGroups[@]}"; do
--output-package "$PACKAGE_NAME/apis/${gv}"
done

# Generate crds.yaml and swagger.json
go run ./hack/gencrd/main.go

popd
87 changes: 79 additions & 8 deletions hack/gencrd/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
package main

import (
"io/ioutil"
"os"

"github.com/appscode/go/log"
"github.com/appscode/go/runtime"
gort "github.com/appscode/go/runtime"
crdutils "github.com/appscode/kutil/apiextensions/v1beta1"
api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
"github.com/appscode/kutil/openapi"
repoinstall "github.com/appscode/searchlight/apis/incidents/install"
incidentv1alpha1 "github.com/appscode/searchlight/apis/incidents/v1alpha1"
stashinstall "github.com/appscode/searchlight/apis/monitoring/install"
slitev1alpha1 "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
"github.com/go-openapi/spec"
"github.com/golang/glog"
crd_api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kube-openapi/pkg/common"
)

func main() {
filename := runtime.GOPath() + "/src/github.com/appscode/searchlight/apis/monitoring/v1alpha1/crds.yaml"
func generateCRDDefinitions() {
filename := gort.GOPath() + "/src/github.com/appscode/searchlight/apis/monitoring/v1alpha1/crds.yaml"

f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
Expand All @@ -20,12 +33,70 @@ func main() {
defer f.Close()

crds := []*crd_api.CustomResourceDefinition{
api.ClusterAlert{}.CustomResourceDefinition(),
api.NodeAlert{}.CustomResourceDefinition(),
api.PodAlert{}.CustomResourceDefinition(),
api.Incident{}.CustomResourceDefinition(),
slitev1alpha1.ClusterAlert{}.CustomResourceDefinition(),
slitev1alpha1.NodeAlert{}.CustomResourceDefinition(),
slitev1alpha1.PodAlert{}.CustomResourceDefinition(),
slitev1alpha1.Incident{}.CustomResourceDefinition(),
}
for _, crd := range crds {
crdutils.MarshallCrd(f, crd, "yaml")
}
}

func generateSwaggerJson() {
var (
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
registry = registered.NewOrDie("")
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
)

stashinstall.Install(groupFactoryRegistry, registry, Scheme)
repoinstall.Install(groupFactoryRegistry, registry, Scheme)

apispec, err := openapi.RenderOpenAPISpec(openapi.Config{
Registry: registry,
Scheme: Scheme,
Codecs: Codecs,
Info: spec.InfoProps{
Title: "stash-server",
Version: "v0",
Contact: &spec.ContactInfo{
Name: "AppsCode Inc.",
URL: "https://appscode.com",
Email: "[email protected]",
},
License: &spec.License{
Name: "Apache 2.0",
URL: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
OpenAPIDefinitions: []common.GetOpenAPIDefinitions{
slitev1alpha1.GetOpenAPIDefinitions,
incidentv1alpha1.GetOpenAPIDefinitions,
},
Resources: []schema.GroupVersionResource{
slitev1alpha1.SchemeGroupVersion.WithResource(slitev1alpha1.ResourcePluralClusterAlert),
slitev1alpha1.SchemeGroupVersion.WithResource(slitev1alpha1.ResourcePluralNodeAlert),
slitev1alpha1.SchemeGroupVersion.WithResource(slitev1alpha1.ResourcePluralPodAlert),
slitev1alpha1.SchemeGroupVersion.WithResource(slitev1alpha1.ResourcePluralIncident),
},
ImmutableResources: []schema.GroupVersionResource{
incidentv1alpha1.SchemeGroupVersion.WithResource(incidentv1alpha1.ResourcePluralAcknowledgement),
},
})
if err != nil {
glog.Fatal(err)
}

filename := gort.GOPath() + "/src/github.com/appscode/searchlight/apis/swagger.json"
err = ioutil.WriteFile(filename, []byte(apispec), 0644)
if err != nil {
glog.Fatal(err)
}
}

func main() {
generateCRDDefinitions()
generateSwaggerJson()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/appscode/kutil/core/v1/pod.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions vendor/github.com/appscode/kutil/core/v1/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions vendor/github.com/appscode/kutil/meta/arguments.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vendor/github.com/appscode/kutil/openapi/getter_storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 89e0070

Please sign in to comment.