-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dsch] issue#37 adding support for schemas without schemaOptions (arr…
…ay of array)
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Bug Fix for: https://github.com/DScheglov/mongoose-schema-jsonschema/issues/37 | ||
* | ||
* Based on the sample taken from the issue | ||
*/ | ||
const mongoose = require('../../index')(require('mongoose')); | ||
|
||
describe('array of array', () => { | ||
const VariableSchema = mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
value: {}, | ||
}); | ||
|
||
const ElementPathSchema = new mongoose.Schema({ | ||
paths: { | ||
paths: { | ||
type: [[VariableSchema]], | ||
validate: { | ||
validator: function validateTemplate(arrayOfVariables) { | ||
return arrayOfVariables.every(variables => VariableSchema.statics.validateTemplate(variables, 'elementQuery')); | ||
}, | ||
message: 'elementPath.paths not valid', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
it('builds the json schema', () => { | ||
expect(ElementPathSchema.jsonSchema()).toEqual({ | ||
type: 'object', | ||
properties: { | ||
paths: { | ||
title: 'paths', | ||
type: 'object', | ||
properties: { | ||
paths: { | ||
type: 'array', | ||
items: { | ||
type: 'array', | ||
items: { | ||
title: 'itemOf_itemOf_paths', | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string' }, | ||
value: {}, | ||
_id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' }, | ||
}, | ||
required: ['name'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
_id: { type: 'string', pattern: '^[0-9a-fA-F]{24}$' }, | ||
}, | ||
}); | ||
}); | ||
}); |