Skip to content

Commit

Permalink
Add fast path for validating non-required undefined fields (bluesky-s…
Browse files Browse the repository at this point in the history
…ocial#2452)

* Add fast path for validating non-required undefined fields

* Fix defaults
  • Loading branch information
gaearon authored Apr 29, 2024
1 parent e306304 commit 6cd572c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/lexicon/src/validators/complex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ export function object(
continue
}
const propDef = def.properties[key]
if (typeof value[key] === 'undefined' && !requiredProps.has(key)) {
// Fast path for non-required undefined props.
if (
propDef.type === 'integer' ||
propDef.type === 'boolean' ||
propDef.type === 'string'
) {
if (typeof propDef.default === 'undefined') {
continue
}
} else {
// Other types have no defaults.
continue
}
}
const propPath = `${path}/${key}`
const validated = validateOneOf(lexicons, propPath, propDef, value[key])
const propValue = validated.success ? validated.value : value[key]
Expand Down

0 comments on commit 6cd572c

Please sign in to comment.