forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genapidocs.go
56 lines (45 loc) · 953 Bytes
/
genapidocs.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
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
yaml "gopkg.in/yaml.v2"
"github.com/go-openapi/loads"
"github.com/openshift/origin/tools/genapidocs/apidocs"
)
func writeAPIDocs(root string) error {
err := os.RemoveAll(root)
if err != nil {
return err
}
doc, err := loads.JSONSpec("api/swagger-spec/openshift-openapi-spec.json")
if err != nil {
return err
}
pages, err := apidocs.BuildPages(doc.Spec())
if err != nil {
return err
}
err = pages.Write(root)
if err != nil {
return err
}
topics := apidocs.BuildTopics(pages)
b, err := yaml.Marshal(topics)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(root, "_topic_map.yml"), b, 0666)
}
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "%s: usage: %[1]s root\n", os.Args[0])
os.Exit(1)
}
err := writeAPIDocs(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
os.Exit(1)
}
}