Prerequisites
🚀 Feature Proposal
When converting mongoose schema toJSONSchema, ObjectIds are converted like so:
_id: { type: 'string' },
However it would be better if they also included the regex validation which could be easily consumed by validators.
Adapting from lib/schema/objectId.js, the JSON schema would be:
"_id": {
"type": "string",
"pattern": "^[A-Fa-f0-9]{24}$"
}
You could also reuse this pattern with $defs/$ref:
https://tour.json-schema.org/content/06-Combining-Subschemas/01-Reusing-and-Referencing-with-defs-and-ref
Motivation
I want to be able to get a portable schema from mongoose with toJSONSchema, and feed it into other validators such as zod, ajv, etc.
Example
No response
Prerequisites
🚀 Feature Proposal
When converting mongoose schema
toJSONSchema, ObjectIds are converted like so:_id: { type: 'string' },However it would be better if they also included the regex validation which could be easily consumed by validators.
Adapting from lib/schema/objectId.js, the JSON schema would be:
You could also reuse this pattern with
$defs/$ref:https://tour.json-schema.org/content/06-Combining-Subschemas/01-Reusing-and-Referencing-with-defs-and-ref
Motivation
I want to be able to get a portable schema from mongoose with
toJSONSchema, and feed it into other validators such aszod,ajv, etc.Example
No response