-
Notifications
You must be signed in to change notification settings - Fork 787
/
schema_writer_generated.go
42 lines (36 loc) · 1.14 KB
/
schema_writer_generated.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
package main
import (
"flag"
"os"
"strings"
openapi "github.com/jenkins-x/jx/pkg/client/openapi/all"
"github.com/go-openapi/spec"
"github.com/pkg/errors"
"github.com/jenkins-x/jx/pkg/kube"
)
func main() {
var outputDir, namesStr, title, version string
flag.StringVar(&outputDir, "output-directory", "", "directory to write generated files to")
flag.StringVar(&namesStr, "names", "", "comma separated list of resources to generate schema for, "+
"if empty all resources will be generated")
flag.StringVar(&title, "title", "", "title for OpenAPI and HTML generated docs")
flag.StringVar(&version, "version", "", "version for OpenAPI and HTML generated docs")
flag.Parse()
if outputDir == "" {
panic(errors.New("--output-directory cannot be empty"))
}
var names []string
if namesStr != "" {
names = strings.Split(namesStr, ",")
} else {
refCallback := func(path string) spec.Ref {
return spec.Ref{}
}
names = openapi.GetNames(refCallback)
}
err := kube.WriteSchemaToDisk(outputDir, title, version, openapi.GetOpenAPIDefinitions, names)
if err != nil {
panic(errors.Wrapf(err, "writing schema to %s", outputDir))
}
os.Exit(0)
}