-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
52 lines (38 loc) · 1.11 KB
/
parse.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
package main
import (
"fmt"
"os"
"github.com/mllrjb/hackathon-go-openapi-v3/generator"
"github.com/mllrjb/hackathon-go-openapi-v3/parser"
"github.com/googleapis/gnostic/OpenAPIv3"
"github.com/googleapis/gnostic/compiler"
)
// const filepath = "examples/demo/components.yaml"
// const filepath = "examples/CaseAPI/cases.yaml"
// const filepath = "examples/demo/polymorphism.yaml"
const filepath = "examples/demo/requests.yaml"
func main() {
bytes, err := compiler.ReadBytesForFile(filepath)
if err != nil {
fmt.Printf("unable to read bytes from %s %s\n", filepath, err)
os.Exit(1)
}
info, err := compiler.ReadInfoFromBytes(filepath, bytes)
if err != nil {
fmt.Printf("unable to read info from %s %s\n", filepath, err)
os.Exit(1)
}
document, err := openapi_v3.NewDocument(info, compiler.NewContext("$root", nil))
if err != nil {
fmt.Printf("unable to parse document %s %s\n", filepath, err)
os.Exit(1)
}
w := parser.NewWalker(document)
err = w.Traverse()
if err != nil {
fmt.Printf("unable to traverse models %s %s\n", filepath, err)
os.Exit(1)
}
generator.GenerateFiles(w)
os.Exit(0)
}