-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (39 loc) · 1.15 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
package main
import (
"encoding/json"
"os"
"path/filepath"
"log"
"github.com/invopop/jsonschema"
"github.com/openchami/schemas/schemas"
"github.com/openchami/schemas/schemas/csm"
)
type InventoryRequest struct {
Header schemas.Envelope `json:"header"`
InventoryDetailArray []schemas.InventoryDetail `json:"inventory_detail_array"`
}
func generateAndWriteSchemas(path string) {
schemas := map[string]interface{}{
"Component.json": &csm.Component{},
"RedfishEndpoint.json": &csm.RedfishEndpoint{},
"InventoryDetailRequest.json": &InventoryRequest{},
}
if err := os.MkdirAll(path, 0755); err != nil {
log.Fatal("Failed to create schema directory")
}
for filename, model := range schemas {
schema := jsonschema.Reflect(model)
data, err := json.MarshalIndent(schema, "", " ")
if err != nil {
log.Fatal("Failed to generate JSON schema")
}
fullpath := filepath.Join(path, filename)
if err := os.WriteFile(fullpath, data, 0644); err != nil {
log.Fatal("Failed to write JSON schema to file")
}
log.Println("Schema written")
}
}
func main() {
generateAndWriteSchemas("jsonschemas")
}