Skip to content

Commit b94fa2d

Browse files
committed
Removed the used of JSONParsingChannel
And moved lock into a position where it can operate correctly. Was locking up vacuum in a multi-tenant fashion. Signed-off-by: Dave Shanley <[email protected]>
1 parent 4b5b964 commit b94fa2d

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

schema_validation/validate_document.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func ValidateOpenAPIDocument(doc libopenapi.Document) (bool, []*liberrors.Valida
2222
info := doc.GetSpecInfo()
2323
loadedSchema := info.APISchema
2424
var validationErrors []*liberrors.ValidationError
25-
<-info.JsonParsingChannel
25+
//<-info.JsonParsingChannel
2626
decodedDocument := *info.SpecJSON
2727

2828
compiler := jsonschema.NewCompiler()

schema_validation/validate_schema.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ var instanceLocationRegex = regexp.MustCompile(`^/(\d+)`)
4848

4949
type schemaValidator struct {
5050
logger *slog.Logger
51+
lock sync.Mutex
5152
}
5253

5354
// NewSchemaValidatorWithLogger will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.
5455
func NewSchemaValidatorWithLogger(logger *slog.Logger) SchemaValidator {
55-
return &schemaValidator{logger: logger}
56+
return &schemaValidator{logger: logger, lock: sync.Mutex{}}
5657
}
5758

5859
// NewSchemaValidator will create a new SchemaValidator instance, ready to accept schemas and payloads to validate.
@@ -64,20 +65,18 @@ func NewSchemaValidator() SchemaValidator {
6465
}
6566

6667
func (s *schemaValidator) ValidateSchemaString(schema *base.Schema, payload string) (bool, []*liberrors.ValidationError) {
67-
return validateSchema(schema, []byte(payload), nil, s.logger)
68+
return s.validateSchema(schema, []byte(payload), nil, s.logger)
6869
}
6970

7071
func (s *schemaValidator) ValidateSchemaObject(schema *base.Schema, payload interface{}) (bool, []*liberrors.ValidationError) {
71-
return validateSchema(schema, nil, payload, s.logger)
72+
return s.validateSchema(schema, nil, payload, s.logger)
7273
}
7374

7475
func (s *schemaValidator) ValidateSchemaBytes(schema *base.Schema, payload []byte) (bool, []*liberrors.ValidationError) {
75-
return validateSchema(schema, payload, nil, s.logger)
76+
return s.validateSchema(schema, payload, nil, s.logger)
7677
}
7778

78-
var renderLock = &sync.Mutex{}
79-
80-
func validateSchema(schema *base.Schema, payload []byte, decodedObject interface{}, log *slog.Logger) (bool, []*liberrors.ValidationError) {
79+
func (s *schemaValidator) validateSchema(schema *base.Schema, payload []byte, decodedObject interface{}, log *slog.Logger) (bool, []*liberrors.ValidationError) {
8180

8281
var validationErrors []*liberrors.ValidationError
8382

@@ -87,20 +86,14 @@ func validateSchema(schema *base.Schema, payload []byte, decodedObject interface
8786
}
8887

8988
// extract index of schema, and check the version
90-
schemaIndex := schema.GoLow().Index
89+
//schemaIndex := schema.GoLow().Index
9190
var renderedSchema []byte
9291

9392
// render the schema, to be used for validation, stop this from running concurrently, mutations are made to state
9493
// and, it will cause async issues.
95-
renderLock.Lock()
96-
97-
//version := float32(0.0)
98-
if schemaIndex != nil {
99-
//version = schemaIndex.GetConfig().SpecInfo.VersionNumeric
100-
101-
}
94+
s.lock.Lock()
10295
renderedSchema, _ = schema.RenderInline()
103-
renderLock.Unlock()
96+
s.lock.Unlock()
10497

10598
jsonSchema, _ := utils.ConvertYAMLtoJSON(renderedSchema)
10699

0 commit comments

Comments
 (0)