Skip to content

Commit e3d4709

Browse files
committed
removed zap! bumped deps
using nothing but good old standard lib now. Signed-off-by: Dave Shanley <[email protected]>
1 parent 37e3a79 commit e3d4709

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

go.mod

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ module github.com/pb33f/libopenapi-validator
33
go 1.21
44

55
require (
6-
github.com/pb33f/libopenapi v0.13.9
6+
github.com/pb33f/libopenapi v0.13.11
77
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
88
github.com/stretchr/testify v1.8.4
99
github.com/vmware-labs/yaml-jsonpath v0.3.2
10-
go.uber.org/zap v1.24.0
1110
gopkg.in/yaml.v3 v3.0.1
1211
)
1312

1413
require (
1514
github.com/davecgh/go-spew v1.1.1 // indirect
1615
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
1716
github.com/pmezard/go-difflib v1.0.0 // indirect
18-
go.uber.org/atomic v1.11.0 // indirect
19-
go.uber.org/multierr v1.11.0 // indirect
2017
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
2118
golang.org/x/sync v0.1.0 // indirect
2219
)

go.sum

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2-
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
31
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
42
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
53
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -49,10 +47,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
4947
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
5048
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
5149
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
52-
github.com/pb33f/libopenapi v0.13.9 h1:LQKTjjhYObuw2RUISbzHx+PH6yueht3mNBx3SBVFjOY=
53-
github.com/pb33f/libopenapi v0.13.9/go.mod h1:Lv2eEtsAtbRFlF8hjH82L8SIGoUNgemMVoKoB6A9THk=
54-
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
55-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
50+
github.com/pb33f/libopenapi v0.13.11 h1:CHRT15/iakHcwRvr9y7bf63UPekXa8FB1Sc4D4BZ7NU=
51+
github.com/pb33f/libopenapi v0.13.11/go.mod h1:Lv2eEtsAtbRFlF8hjH82L8SIGoUNgemMVoKoB6A9THk=
5652
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5753
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5854
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
@@ -67,14 +63,6 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
6763
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
6864
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
6965
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
70-
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
71-
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
72-
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
73-
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
74-
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
75-
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
76-
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
77-
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
7866
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
7967
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
8068
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

schema_validation/validate_schema.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import (
1414
"github.com/pb33f/libopenapi/utils"
1515
"github.com/santhosh-tekuri/jsonschema/v5"
1616
_ "github.com/santhosh-tekuri/jsonschema/v5/httploader"
17-
"go.uber.org/zap"
1817
"gopkg.in/yaml.v3"
18+
"log/slog"
19+
"os"
1920
"reflect"
2021
"regexp"
2122
"strconv"
@@ -46,13 +47,20 @@ type SchemaValidator interface {
4647
var instanceLocationRegex = regexp.MustCompile(`^/(\d+)`)
4748

4849
type schemaValidator struct {
49-
logger *zap.SugaredLogger
50+
logger *slog.Logger
51+
}
52+
53+
// NewSchemaValidatorWithLogger will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.
54+
func NewSchemaValidatorWithLogger(logger *slog.Logger) SchemaValidator {
55+
return &schemaValidator{logger: logger}
5056
}
5157

5258
// NewSchemaValidator will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.
5359
func NewSchemaValidator() SchemaValidator {
54-
logger, _ := zap.NewProduction()
55-
return &schemaValidator{logger: logger.Sugar()}
60+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
61+
Level: slog.LevelError,
62+
}))
63+
return NewSchemaValidatorWithLogger(logger)
5664
}
5765

5866
func (s *schemaValidator) ValidateSchemaString(schema *base.Schema, payload string) (bool, []*liberrors.ValidationError) {
@@ -69,12 +77,12 @@ func (s *schemaValidator) ValidateSchemaBytes(schema *base.Schema, payload []byt
6977

7078
var renderLock = &sync.Mutex{}
7179

72-
func validateSchema(schema *base.Schema, payload []byte, decodedObject interface{}, log *zap.SugaredLogger) (bool, []*liberrors.ValidationError) {
80+
func validateSchema(schema *base.Schema, payload []byte, decodedObject interface{}, log *slog.Logger) (bool, []*liberrors.ValidationError) {
7381

7482
var validationErrors []*liberrors.ValidationError
7583

7684
if schema == nil {
77-
log.Infoln("schema is empty and cannot be validated. This generally means the schema is missing from the spec, or could not be read.")
85+
log.Info("schema is empty and cannot be validated. This generally means the schema is missing from the spec, or could not be read.")
7886
return false, validationErrors
7987
}
8088

@@ -124,15 +132,6 @@ func validateSchema(schema *base.Schema, payload []byte, decodedObject interface
124132
}
125133
compiler := jsonschema.NewCompiler()
126134

127-
// setting this will break existing vacuum OWASP rules, that assume a 2020 validator for if/else/then schema
128-
// validations.
129-
//switch version {
130-
//case 3.0, 2.0:
131-
// compiler.Draft = jsonschema.Draft4
132-
//default:
133-
// compiler.Draft = jsonschema.Draft2020
134-
//}
135-
136135
_ = compiler.AddResource("schema.json", strings.NewReader(string(jsonSchema)))
137136
jsch, err := compiler.Compile("schema.json")
138137

0 commit comments

Comments
 (0)