From 72badb2e5e33a6a76c7cb1115d1d49ff0fb9e0fb Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sun, 29 Dec 2024 13:28:30 +0900 Subject: [PATCH] chore: update JSON Schema (#3397) --- cmd/gen-jsonschema/main.go | 36 +++++++----------------------------- go.mod | 3 ++- go.sum | 2 ++ json-schema/aqua-yaml.json | 3 +++ 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/cmd/gen-jsonschema/main.go b/cmd/gen-jsonschema/main.go index 522e6532a..c8c06c25e 100644 --- a/cmd/gen-jsonschema/main.go +++ b/cmd/gen-jsonschema/main.go @@ -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() { @@ -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(®istry.Config{}, "json-schema/registry.json"); err != nil { - return err + if err := jsonschema.Write(®istry.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 } diff --git a/go.mod b/go.mod index 065a4fd14..4a72c7e93 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 30923d9cd..8a0226f3f 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/json-schema/aqua-yaml.json b/json-schema/aqua-yaml.json index 70a0c5c0e..3368da50e 100644 --- a/json-schema/aqua-yaml.json +++ b/json-schema/aqua-yaml.json @@ -100,6 +100,9 @@ "version_expr": { "type": "string" }, + "version_expr_prefix": { + "type": "string" + }, "vars": { "type": "object" },