-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
107 lines (94 loc) · 3.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Copyright The Stash Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"io/ioutil"
"os"
"path/filepath"
repoinstall "stash.appscode.dev/apimachinery/apis/repositories/install"
repov1alpha1 "stash.appscode.dev/apimachinery/apis/repositories/v1alpha1"
stashinstall "stash.appscode.dev/apimachinery/apis/stash/install"
stashv1alpha1 "stash.appscode.dev/apimachinery/apis/stash/v1alpha1"
stashv1beta1 "stash.appscode.dev/apimachinery/apis/stash/v1beta1"
gort "github.com/appscode/go/runtime"
"github.com/go-openapi/spec"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kube-openapi/pkg/common"
"kmodules.xyz/client-go/openapi"
)
func generateSwaggerJson() {
var (
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)
)
stashinstall.Install(Scheme)
repoinstall.Install(Scheme)
apispec, err := openapi.RenderOpenAPISpec(openapi.Config{
Scheme: Scheme,
Codecs: Codecs,
Info: spec.InfoProps{
Title: "Stash",
Version: "v0.9.0-rc.0",
Contact: &spec.ContactInfo{
Name: "AppsCode Inc.",
URL: "https://appscode.com",
Email: "hello@appscode.com",
},
License: &spec.License{
Name: "Apache 2.0",
URL: "https://www.apache.org/licenses/LICENSE-2.0.html",
},
},
OpenAPIDefinitions: []common.GetOpenAPIDefinitions{
stashv1alpha1.GetOpenAPIDefinitions,
stashv1beta1.GetOpenAPIDefinitions,
repov1alpha1.GetOpenAPIDefinitions,
},
//nolint:govet
Resources: []openapi.TypeInfo{
// v1alpha1 resources
{stashv1alpha1.SchemeGroupVersion, stashv1alpha1.ResourcePluralRestic, stashv1alpha1.ResourceKindRestic, true},
{stashv1alpha1.SchemeGroupVersion, stashv1alpha1.ResourcePluralRepository, stashv1alpha1.ResourceKindRepository, true},
{stashv1alpha1.SchemeGroupVersion, stashv1alpha1.ResourcePluralRecovery, stashv1alpha1.ResourceKindRecovery, true},
// v1beta1 resources
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourcePluralBackupConfiguration, stashv1beta1.ResourceKindBackupConfiguration, true},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourceKindBackupSession, stashv1beta1.ResourceKindBackupSession, true},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourceKindBackupBatch, stashv1beta1.ResourceKindBackupBatch, false},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourceKindBackupBlueprint, stashv1beta1.ResourceKindBackupBlueprint, false},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourcePluralRestoreSession, stashv1beta1.ResourceKindRestoreSession, true},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourceKindFunction, stashv1beta1.ResourceKindFunction, false},
{stashv1beta1.SchemeGroupVersion, stashv1beta1.ResourcePluralTask, stashv1beta1.ResourceKindTask, false},
},
//nolint:govet
RDResources: []openapi.TypeInfo{
{repov1alpha1.SchemeGroupVersion, repov1alpha1.ResourcePluralSnapshot, repov1alpha1.ResourceKindSnapshot, true},
},
})
if err != nil {
glog.Fatal(err)
}
filename := gort.GOPath() + "/src/stash.appscode.dev/apimachinery/api/openapi-spec/swagger.json"
err = os.MkdirAll(filepath.Dir(filename), 0755)
if err != nil {
glog.Fatal(err)
}
err = ioutil.WriteFile(filename, []byte(apispec), 0644)
if err != nil {
glog.Fatal(err)
}
}
func main() {
generateSwaggerJson()
}