Mongoose Model to Alpaca Schema Converter
Convert Mongoose model definitions to Alpaca Forms JSON schema, options, and data objects. Supports nested schemas, validators, enums, refs, and arrays.
// Schema output will appear here
// Options output will appear here
// Data output will appear here
// Full Alpaca config will appear here
About
Mongoose schemas define document structure for MongoDB. Alpaca Forms renders JSON Schema as interactive HTML forms. Bridging these two requires mapping Mongoose types (String, Number, ObjectId, nested objects, arrays) to their JSON Schema equivalents (string, number, object, array) while preserving validators: required, min, max, enum, match (converted to pattern), and default values. Manual conversion is error-prone. A missing required flag or mismatched enum array means your form silently accepts invalid data that your database will reject at write time. This tool parses Mongoose-style schema definitions and outputs a complete Alpaca configuration object with schema, options, and data sections ready for Alpaca rendering.
Limitations: this tool approximates Mongoose schema syntax from plain object notation. It does not execute JavaScript, so dynamic defaults (functions), custom validators with callbacks, virtuals, middleware, and Schema.plugin() calls are not converted. Discriminators and refPath dynamic references produce a basic string type. The parser handles the structural subset that maps cleanly to JSON Schema.
Formulas
The converter applies a deterministic mapping function f from each Mongoose field descriptor M to an Alpaca triple (S, O, D) representing schema, options, and data:
Where S = JSON Schema fragment with type, enum, minimum, maximum, minLength, maxLength, pattern, format, default. O = Alpaca options fragment with type (control type), label, helper, placeholder. D = default data value extracted from default property if it is a literal (non-function).
For nested objects, the function recurses:
For arrays [T], the schema becomes type = "array" with items = f(T). The required array at each object level is populated by collecting all field keys where required = TRUE in the Mongoose descriptor.
Reference Data
| Mongoose Type | JSON Schema Type | Alpaca Format | Validators Mapped | Notes |
|---|---|---|---|---|
| String | string | text | minlength, maxlength, enum, match | match → pattern |
| Number | number | number | min, max | Integer detection not automatic |
| Boolean | boolean | checkbox | - | Default mapped if present |
| Date | string | date | min, max | Format set to date |
| ObjectId | string | text | ref | Ref stored in options label |
| Buffer | string | file | - | Binary data as file upload |
| Mixed / Schema.Types.Mixed | any | any | - | No validation enforced |
| Map | object | object | - | additionalProperties from of |
| [String] | array of string | array | Array-level validators | Items schema generated |
| [{ nested }] | array of object | array | Recursive parsing | Full nested schema in items |
| Nested { field: { ... } } | object | object | Recursive parsing | Properties generated recursively |
| Decimal128 | number | number | min, max | High-precision decimal |
| Int32 | integer | integer | min, max | Explicit integer type |