Skip to content

Commit

Permalink
chore: update JSON Schema (#3397)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke authored Dec 29, 2024
1 parent e0c783a commit 72badb2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
36 changes: 7 additions & 29 deletions cmd/gen-jsonschema/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package main

import (
"encoding/json"
"fmt"
"log"
"os"
"strings"

"github.com/aquaproj/aqua/v2/pkg/config/aqua"
"github.com/aquaproj/aqua/v2/pkg/config/registry"
"github.com/aquaproj/aqua/v2/pkg/policy"
"github.com/invopop/jsonschema"
"github.com/suzuki-shunsuke/gen-go-jsonschema/jsonschema"
)

func main() {
Expand All @@ -20,33 +17,14 @@ func main() {
}

func core() error {
if err := gen(&aqua.Config{}, "json-schema/aqua-yaml.json"); err != nil {
return err
if err := jsonschema.Write(&aqua.Config{}, "json-schema/aqua-yaml.json"); err != nil {
return fmt.Errorf("create or update a JSON Schema: %w", err)
}
if err := gen(&registry.Config{}, "json-schema/registry.json"); err != nil {
return err
if err := jsonschema.Write(&registry.Config{}, "json-schema/registry.json"); err != nil {
return fmt.Errorf("create or update a JSON Schema: %w", err)
}
if err := gen(&policy.ConfigYAML{}, "json-schema/policy.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,mnd
return fmt.Errorf("write JSON Schema to %s: %w", p, err)
if err := jsonschema.Write(&policy.ConfigYAML{}, "json-schema/policy.json"); err != nil {
return fmt.Errorf("create or update a JSON Schema: %w", err)
}
return nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/aquaproj/aqua/v2

go 1.23.2
go 1.23.4

require (
github.com/Masterminds/sprig/v3 v3.3.0
Expand All @@ -21,6 +21,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.11.0
github.com/suzuki-shunsuke/flute v1.0.1
github.com/suzuki-shunsuke/gen-go-jsonschema v0.1.0
github.com/suzuki-shunsuke/go-error-with-exit-code v1.0.0
github.com/suzuki-shunsuke/go-findconfig v1.2.0
github.com/suzuki-shunsuke/go-osenv v0.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/suzuki-shunsuke/flute v1.0.1 h1:qzxSX2WQ8ih378zeCrjDMW5mVCsYyEmjicYuCy4aiLk=
github.com/suzuki-shunsuke/flute v1.0.1/go.mod h1:lQKcCgbjiIzH4lar2V2UX1IdEwAB5KTfTckgWN1rtFg=
github.com/suzuki-shunsuke/gen-go-jsonschema v0.1.0 h1:g7askc+nskCkKRWTVOdsAT8nMhwiaVT6Dmlnh6uvITM=
github.com/suzuki-shunsuke/gen-go-jsonschema v0.1.0/go.mod h1:yFO7h5wwFejxi6jbtazqmk7b/JSBxHcit8DGwb1bhg0=
github.com/suzuki-shunsuke/go-cliutil v0.0.0-20181211154308-176f852d9bca/go.mod h1:Vq3NkhgmA9DT/2UZ08x/3A34xxvzQ/vTMABnTWKoMbY=
github.com/suzuki-shunsuke/go-error-with-exit-code v1.0.0 h1:oVXrrYNGBq4POyITQNWKzwsYz7B2nUcqtDbeX4BfeEc=
github.com/suzuki-shunsuke/go-error-with-exit-code v1.0.0/go.mod h1:kDFtLeftDiIUUHXGI3xq5eJ+uAOi50FPrxPENTHktJ0=
Expand Down
3 changes: 3 additions & 0 deletions json-schema/aqua-yaml.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
"version_expr": {
"type": "string"
},
"version_expr_prefix": {
"type": "string"
},
"vars": {
"type": "object"
},
Expand Down

0 comments on commit 72badb2

Please sign in to comment.