-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 937 Bytes
/
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
package main
import (
"flag"
"github.com/lambdasawa/microcms-sdk-generator/metadata"
"github.com/lambdasawa/microcms-sdk-generator/microcms"
"github.com/lambdasawa/microcms-sdk-generator/openapi"
)
func main() {
var inputFilePath, outputFilePath string
flag.StringVar(&inputFilePath, "input", "metadata.yml", "input file path")
flag.StringVar(&outputFilePath, "output", "openapi.yml", "output file path")
flag.Parse()
meta, err := metadata.LoadFromFile(inputFilePath)
if err != nil {
panic(err)
}
microCMSSchemaMap := map[string]microcms.Schema{}
for _, api := range meta.APIs {
schema, err := microcms.LoadSchemaFromFile(api.BuildPath(meta))
if err != nil {
panic(err)
}
microCMSSchemaMap[api.Name] = schema
}
openapiSchema, err := openapi.BuildFrom(meta, microCMSSchemaMap)
if err != nil {
panic(err)
}
if err := openapi.SaveAsFile(openapiSchema, outputFilePath); err != nil {
panic(err)
}
}