Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Ref objects (within array or as a sub document) works? #44

Open
talbensimhon71 opened this issue Sep 20, 2017 · 0 comments
Open

Does Ref objects (within array or as a sub document) works? #44

talbensimhon71 opened this issue Sep 20, 2017 · 0 comments

Comments

@talbensimhon71
Copy link

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"
      }
    }
  }
}

}
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant