forked from jsonnet-libs/k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (67 loc) · 1.62 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
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"path/filepath"
"github.com/jsonnet-libs/k8s/pkg/docs"
"github.com/jsonnet-libs/k8s/pkg/model"
"github.com/jsonnet-libs/k8s/pkg/render"
"github.com/jsonnet-libs/k8s/pkg/swagger"
)
func main() {
spec := flag.String("spec", "swagger.json", "path to openapi spec")
dir := flag.String("dir", "k8s", "output path")
flag.Parse()
if err := os.MkdirAll(*dir, os.ModePerm); err != nil {
log.Fatalln(err)
}
data, err := ioutil.ReadFile(*spec)
if err != nil {
log.Fatalln(err)
}
s, err := swagger.Load(data)
if err != nil {
log.Fatalln(err)
}
groups := model.Load(s)
if err := genDocs(groups, *dir); err != nil {
log.Fatalln(err)
}
}
func genDocs(groups map[string]model.Group, dir string) error {
for name, grp := range groups {
path := filepath.Join(dir, name)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
overview := docs.Group(name, grp)
if err := ioutil.WriteFile(filepath.Join(path, "README.md"), []byte(overview), 0644); err != nil {
return err
}
for verName, ver := range grp {
for name, kind := range ver.Kinds {
kindMd := docs.Kind(name, kind)
if err := ioutil.WriteFile(
filepath.Join(path, verName+"."+name+".md"),
[]byte(kindMd),
0644,
); err != nil {
return err
}
}
}
}
return nil
}
func jsonnet(groups map[string]model.Group, dir string) error {
for name, group := range groups {
o := render.Group(name, group)
file := filepath.Join(dir, name+".libsonnet")
if err := ioutil.WriteFile(file, []byte(o.String()), 0644); err != nil {
return err
}
}
return nil
}