fix(schema): Add enumValues support to SchemaBuffer (consistency with String/Number) #15846
+112
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15845
This PR adds
enumValuessupport to SchemaBuffer so that buffer enum behavior becomes consistent with SchemaString and SchemaNumber.Background
SchemaBuffer previously allowed enum validation but did not expose an
enumValuesarray or fully support the.enum()API pattern used by other schema types. This created an inconsistency where buffer enums could validate values, but the allowed values could not be introspected or extended using additional.enum()calls.What this PR changes
this.enumValues = []in the SchemaBuffer constructor.SchemaBuffer.prototype.enum()following the same structure asSchemaNumber.prototype.enum():{ values, message }.this.cast(...)before storing.this.enumValues.Buffer.compare.this.validators.thisfor method chaining.Tests
A new test has been added to
test/schema.validation.test.jsthat mirrors the structure of the existing string and number enum tests and verifies:enumValuesis correctly populated on schema paths..enum()behavior works (enum('c')appends).{ values, message }) is supported.nullandundefinedbehave consistently with other SchemaTypes.Why this change is needed
This is an API consistency improvement. String and Number schema types already support:
enumValuesexposure.enum().enum()with no argsThis PR brings SchemaBuffer up to the same standard without introducing breaking changes.
Notes
schema/buffer.js.