From 7b0ed3c46f1e8d2f33e8b4a2f472f9af8bffec2b Mon Sep 17 00:00:00 2001 From: braydonk Date: Sat, 24 Aug 2024 13:38:39 +0000 Subject: [PATCH 1/2] Add JSON schema validity test --- go.mod | 5 +++++ go.sum | 4 ++++ internal/jsonschema/schema_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 internal/jsonschema/schema_test.go diff --git a/go.mod b/go.mod index 874a519..e8aeb0d 100644 --- a/go.mod +++ b/go.mod @@ -9,3 +9,8 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 ) + +require ( + github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect + golang.org/x/text v0.14.0 // indirect +) diff --git a/go.sum b/go.sum index 4c2e06f..c95f917 100644 --- a/go.sum +++ b/go.sum @@ -12,9 +12,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/internal/jsonschema/schema_test.go b/internal/jsonschema/schema_test.go new file mode 100644 index 0000000..5fcbd15 --- /dev/null +++ b/internal/jsonschema/schema_test.go @@ -0,0 +1,29 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package jsonschema_test + +import ( + "testing" + + "github.com/santhosh-tekuri/jsonschema/v6" +) + +func TestJSONSchemaIsValid(t *testing.T) { + c := jsonschema.NewCompiler() + _, err := c.Compile("../../schema.json") + if err != nil { + t.Fatalf("JSON schema failed to compile: %v", err) + } +} From 97677debe81623791307c7ef7c01114549d20be7 Mon Sep 17 00:00:00 2001 From: braydonk Date: Sat, 24 Aug 2024 13:46:41 +0000 Subject: [PATCH 2/2] switch to package v4 for go 1.18 compatibility --- go.mod | 5 +---- go.sum | 2 ++ internal/jsonschema/schema_test.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index e8aeb0d..7e359ee 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,4 @@ require ( github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 ) -require ( - github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect - golang.org/x/text v0.14.0 // indirect -) +require github.com/santhosh-tekuri/jsonschema/v4 v4.0.0 // indirect diff --git a/go.sum b/go.sum index c95f917..68e40f7 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= +github.com/santhosh-tekuri/jsonschema/v4 v4.0.0 h1:5yvbsmEfOQE2+YuRudUhXPzMQK6P74AR3LafM5zrzf0= +github.com/santhosh-tekuri/jsonschema/v4 v4.0.0/go.mod h1:P2UNYJ2xnL4zRyQ2obmD35HiejSJhHTKwMcckhPucG4= github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/jsonschema/schema_test.go b/internal/jsonschema/schema_test.go index 5fcbd15..59eb453 100644 --- a/internal/jsonschema/schema_test.go +++ b/internal/jsonschema/schema_test.go @@ -17,7 +17,7 @@ package jsonschema_test import ( "testing" - "github.com/santhosh-tekuri/jsonschema/v6" + "github.com/santhosh-tekuri/jsonschema/v4" ) func TestJSONSchemaIsValid(t *testing.T) {