Skip to content

Commit

Permalink
Use "id" as the identifier property for Draft3
Browse files Browse the repository at this point in the history
See: #83
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Nov 2, 2022
1 parent 8733f80 commit 6adb824
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bindings/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) {
return true
}

if (_.has(root, trail.path.concat(from === 'draft4' ? 'id' : '$id'))) {
if (_.has(root, trail.path.concat(jsonschema.getIdProperty(from)))) {
return false
}
}
Expand Down
6 changes: 5 additions & 1 deletion bindings/node/jsonschema.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ exports.usesVocabulary = (_root, value, _vocabulary) => {
return false
}

exports.getIdProperty = (version) {
return [ 'draft3', 'draft4' ].includes(version) ? 'id' : '$id'
}

exports.matches = async (schema, value) => {
const idProperty = METASCHEMAS[schema.$schema] === 'draft4' ? 'id' : '$id'
const idProperty = exports.getIdProperty(METASCHEMAS[schema.$schema])
jsonschema.add(schema)
const result = await jsonschema.validate(jsonschema.get(schema[idProperty]), value)
return result.valid
Expand Down

0 comments on commit 6adb824

Please sign in to comment.