Skip to content

Commit

Permalink
fix: SchemasMatch handling null (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpears201 authored Jul 10, 2024
1 parent 5e7cda8 commit 07c47db
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/validate/validator/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const addFailingMethodSchema = (error, json, schema) => {
const i = parseInt(error.schemaPath.split("/")[2])
error.params.failingSchema = schema.definitions.Method.allOf[i].then.$ref
}
}

}
}
}

Expand All @@ -61,7 +61,7 @@ export const pruneErrors = (errors = []) => {

Object.values(groups).forEach( group => {
const paths = []
pruned.push(group.sort( (a, b) => b.schemaPath.split('/').length - a.schemaPath.split('/').length ).pop())
pruned.push(group.sort( (a, b) => b.schemaPath.split('/').length - a.schemaPath.split('/').length ).pop())
})

return pruned
Expand Down Expand Up @@ -163,12 +163,18 @@ export const validate = (json = {}, schemas = {}, ajv, validator, additionalPack
validator.errors.forEach(error => error.source = 'OpenRPC')

errors.push(...pruneErrors(validator.errors))
}
}

return { valid: valid, title: json.title || json.info.title, errors: errors }
}

const schemasMatch = (a, b) => {
if (a == null) {
return b == null
}
if (b == null) {
return a == null
}
const aKeys = Object.keys(a)
const bKeys = Object.keys(b)
const keysMatch = (aKeys.length == bKeys.length) && aKeys.every(key => bKeys.includes(key))
Expand Down Expand Up @@ -229,7 +235,7 @@ export const validatePasshtroughs = (json) => {

if (!schemasMatch(source, destination)) {
const properties = getPropertiesInSchema(destination, json)

// follow $refs so we can see the schemas
source = getPropertySchema(source, '.', json)
destination = getPropertySchema(destination, '.', json)
Expand Down Expand Up @@ -270,4 +276,4 @@ export const validatePasshtroughs = (json) => {

return result

}
}

0 comments on commit 07c47db

Please sign in to comment.