Skip to content

Commit

Permalink
feat: error on missing schema refs
Browse files Browse the repository at this point in the history
Reformat tv4's missing schema output to match the expected validation
error format
  • Loading branch information
joaosa committed Mar 3, 2017
1 parent 13d916d commit ee7d7aa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/validators/json-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,23 @@ class JsonSchema
#@private
validateSchemaV4: =>
result = tv4.validateMultiple @data, @schema
validationErrors = result.errors.concat result.missing

amandaCompatibleError =
length: result.errors.length
length: validationErrors.length
errorMessages: {}

for error, index in result?.errors
for err, index in validationErrors
# Need to create the error in case of missing schema errors.
# If tv4 meets $ref to a missing schema, it provides an array that contains the schema's domain.
# In case we a local $ref, as there's no domain name, it will look like this: ['', '': '']
if err instanceof Error
error = err
else
error = new Error('Missing schema')
error.params = { key: err }
error.dataPath = ''

pathArray = jsonPointer.parse error.dataPath
if error.params.key
pathArray.push error.params.key
Expand Down

0 comments on commit ee7d7aa

Please sign in to comment.