Skip to content

Commit fcb62d5

Browse files
martinsirbedaveshanley
authored andcommitted
Check and handle compiler err on compile req body
1 parent 261b77d commit fcb62d5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

requests/validate_request.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ func ValidateRequestSchema(
9797

9898
compiler := jsonschema.NewCompiler()
9999
_ = compiler.AddResource("requestBody.json", strings.NewReader(string(jsonSchema)))
100-
jsch, _ := compiler.Compile("requestBody.json")
100+
jsch, err := compiler.Compile("requestBody.json")
101+
if err != nil {
102+
validationErrors = append(validationErrors, &errors.ValidationError{
103+
ValidationType: helpers.RequestBodyValidation,
104+
ValidationSubType: helpers.Schema,
105+
Message: err.Error(),
106+
Reason: "Failed to compile the request body for validation.",
107+
Context: string(renderedSchema),
108+
})
109+
return false, validationErrors
110+
}
101111

102112
// validate the object against the schema
103113
scErrs := jsch.Validate(decodedObj)

0 commit comments

Comments
 (0)