feat(model): add standard schema adapter for models - #16308
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for the Standard Schema v1 ~standard adapter on Mongoose models, enabling model-based validation that returns Standard Schema-compatible { value } / { issues } results (Fixes #16280).
Changes:
- Add
Model['~standard']runtime implementation that wrapsModel.validate()and converts Mongoose validation errors into Standard Schema issue arrays. - Add TypeScript declarations for
mongoose.StandardSchemaV1and theModel['~standard']property. - Add runtime + type-level tests covering success/failure results,
pathsToSkip, and discriminator behavior.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| types/models.d.ts | Defines StandardSchemaV1 types and adds Model['~standard'] to the public model type surface. |
| test/types/models.test.ts | Adds type tests asserting adapter shape and result typing/narrowing behavior. |
| test/model.validate.test.js | Adds runtime tests for Standard Schema result format, pathsToSkip, and discriminator support. |
| lib/standardSchema/convertErrorToIssues.js | Converts Mongoose ValidationError into Standard Schema issues with array-based path. |
| lib/model.js | Implements Model['~standard'] via a getter that wraps Model.validate() and formats results. |
hasezoey
approved these changes
May 29, 2026
hasezoey
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me from a mongoose perspective, i dont know if it is correct according to Standard Schema though.
hasezoey
reviewed
Jun 4, 2026
|
|
||
| /** | ||
| * Standard Schema adapter for this model. | ||
| * Calls [`Model.validate()`](#Model.validate()) internally with the provided `libraryOptions` |
Collaborator
There was a problem hiding this comment.
This link got messed up.
Nevermind, didnt see the closing ), still all links should start with mongoosejs.com as they are replaced automatically and so can work in jsdoc too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix #16280
cc @ssalbdivad
Summary
Support for
~standardvalidate adapter. See standard schema docs.Outstanding questions:
User['~standard'].validate({ age: '42' })ok given that Mongoose will convert string'42'to number42and return the result inresult?Examples