-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (39 loc) · 975 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
40
41
42
43
44
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
"github.com/invopop/jsonschema"
"github.com/suzuki-shunsuke/renovate-issue-action/pkg/config"
)
func main() {
if err := core(); err != nil {
log.Fatal(err)
}
}
func core() error {
if err := gen(&config.Config{}, "json-schema/config.json"); err != nil {
return err
}
return nil
}
func gen(input interface{}, p string) error {
f, err := os.Create(p)
if err != nil {
return fmt.Errorf("create a file %s: %w", p, err)
}
defer f.Close()
encoder := json.NewEncoder(f)
encoder.SetIndent("", " ")
s := jsonschema.Reflect(input)
b, err := json.MarshalIndent(s, "", " ")
if err != nil {
return fmt.Errorf("mashal schema as JSON: %w", err)
}
if err := os.WriteFile(p, []byte(strings.ReplaceAll(string(b), "http://json-schema.org", "https://json-schema.org")+"\n"), 0o644); err != nil { //nolint:gosec,gomnd
return fmt.Errorf("write JSON Schema to %s: %w", p, err)
}
return nil
}