forked from kristianmandrup/convert-json-schema-to-mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
32 lines (29 loc) · 810 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import createMongooseSchema from './lib/json-schema';
const refs = {
yep: {
type: 'string', pattern: '^\\d{3}$'
}, a: {
type: 'array', items: {
type: 'object', properties: {
num: {type: 'number'}, str: {type: 'string'}
}
}
}, idSpec: {
type: 'object', properties: {
id: {$ref: 'yep'}, arr: {$ref: 'a'}
}
}
};
// noinspection ReservedWordAsName
const valid = {
type: 'object', properties: {
id: {$ref: 'yep'}, arr: {$ref: 'a'}, address: {
type: 'object', properties: {
street: {type: 'integer', default: 44, minimum: 0, maximum: 50},
houseColor: {type: 'string', default: '[Function=Date.now]', format: 'date-time'}
}
}
}
};
const result = createMongooseSchema(refs, valid);
console.dir(result, {depth: null});