Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SchemasMatch handling null #199

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

}
}
Loading