@@ -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 {
4647var instanceLocationRegex = regexp .MustCompile (`^/(\d+)` )
4748
4849type 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.
5359func 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
5866func (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
7078var 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