Does Ref objects (within array or as a sub document) works?
talbensimhon71 opened this issue · comments
I always get the cast Error, the schema compiled but it is not working.
This is when trying to save a sub array which its items are $ref...
error ValidationError: children: Cast to Array failed for value "[ { firstName: 'Sagi' }, { firstName: 'Tamir' } ]" at path "children"
and this is when saving a sub document which is from type object
error ValidationError: child1: Cast to ObjectID failed for value "{ firstName: 'Sagi' }" at path "child1"
Here is the JSON:
`{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "accounts",
"contact": {
"name": "",
"email": "test@gmail.com"
},
"license": {
"name": "The MIT License (MIT)",
"url": "https://opensource.org/licenses/MIT"
}
},
"basePath": "/database/schemes",
"schemes": [
"http"
],
"x-swagger-mongoose": {
"validators": "./api/system/database/schemas/validators",
"description": "The relative path to validators library from process.cwd()"
},
"paths": {
"/parents": {
"get": {
"tags": [
"parents Operations"
],
"summary": "finds parents in the system",
"responses": {
"200": {
"description": "parents response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/parent"
}
},
"headers": {
"x-expires": {
"type": "string"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"parent": {
"required": [
"firstName",
"lastName"
],
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"child1": {
"type": "object",
"x-swagger-mongoose": {
"$ref": "#/definitions/child"
}},
"child2": {
"type": "object",
"properties":{
"firstName":{
"type": "string"
}
}
},
"children": {
"type": "array",
"items": {
"x-swagger-mongoose": {
"$ref": "#/definitions/child"
}
}
}
},
"child": {
"required": [
"firstName"
],
"properties": {
"_id": {
"type": "string"
},
"firstName": {
"type": "string"
}
}
}
}
}
}`