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

No implicit conversion of integer #259

Closed
wjdhamilton opened this issue Jul 8, 2015 · 4 comments
Closed

No implicit conversion of integer #259

wjdhamilton opened this issue Jul 8, 2015 · 4 comments

Comments

@wjdhamilton
Copy link

I'm more than willing to suppose that I am doing something wrong, but whenever I try and validate the following string:
{ "friend": { "id": 1, "name": "Roman Graham", "email": "ro.willms@carroll.org", "dob": "1995-05-05", "gender": true }, "links": { "id": "/friends/1", "relationships": "/friends/1/relationships", "occasions": "/friends/1/occasions" } }

with this schema:

{ "id": "http://www.occasions.me/schemas/friends", "type": "object", "properties": { "friend": { "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "email": { "type": "string" }, "dob": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }, "gender": { "type": "boolean" } }, "required": [ "name", "email" ] }, "links": [{ "rel": "full", "href": "{id}" }, { "rel": "relationships", "href": "/friends/{id}/relationships" }, { "rel": "occasions", "href": "/friends/{id}/occasions" }, { "rel": "address", "href": "/addresses/{address_id}" }] } }

I get the following error:

Failure/Error: expect(response).to match_response_schema :friend_schema TypeError: no implicit conversion of String into Integer

...and it's doing my head in. The runtime error only occurs when id is specified as an integer. If I specify it as a string it predictably fails validation. Can anyone tell me where I'm going wrong or have I found a bug?

@iainbeeston
Copy link
Contributor

I think that in your schemes friends and links are also objects - you need
to define them as such with type: object
On Wed, 8 Jul 2015 at 8:57 pm, wjdhamilton notifications@github.com wrote:

I'm more than willing to suppose that I am doing something wrong, but
whenever I try and validate the following string:
{
"friend": {
"id": 1,
"name": "Roman Graham",
"email": "ro.willms@carroll.org",
"dob": "1995-05-05",
"gender": true
},
"links": {
"id": "/friends/1",
"relationships": "/friends/1/relationships",
"occasions": "/friends/1/occasions"
}
}

with this schema:

{
"id": "http://www.occasions.me/schemas/friends",
"type": "object",
"properties": {
"friend": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"dob": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
},
"gender": {
"type": "boolean"
}
},
"required": [
"name",
"email"
]
},
"links": [{
"rel": "full",
"href": "{id}"
}, {
"rel": "relationships",
"href": "/friends/{id}/relationships"
}, {
"rel": "occasions",
"href": "/friends/{id}/occasions"
}, {
"rel": "address",
"href": "/addresses/{address_id}"
}]
}
}

I get the following error:

Failure/Error: expect(response).to match_response_schema :friend_schema
TypeError:
no implicit conversion of String into Integer

...and it's doing my head in. The runtime error only occurs when id is
specified as an integer. If I specify it as a string it predictably fails
validation. Can anyone tell me where I'm going wrong or have I found a bug?


Reply to this email directly or view it on GitHub
#259.

@wjdhamilton
Copy link
Author

Hi Iain,

Thanks for the help. I've rewritten the schema as follows:

{ "id": "http://www.occasions.me/schemas/friends", "type": "object", "properties": { "friend": { "properties": { "id": { "type": "number" }, "name": { "type": "string" }, "email": { "type": "string" }, "dob": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }, "gender": { "type": "boolean" }, "links": { "type": "object", "properties": { "id": "string", "relationships": "string", "occasions": "string" } } } } } }

...but now I get the following error:
undefined method `each' for "string":String

@iainbeeston
Copy link
Contributor

My bad, your links property is an array of objects, not an object.

If it helps, I recommend this guide to Jason schema:

http://spacetelescope.github.io/understanding-json-schema/index.html
On Fri, 10 Jul 2015 at 2:08 pm, wjdhamilton notifications@github.com
wrote:

Hi Iain,

Thanks for the help. I've rewritten the schema as follows:

{
"id": "http://www.occasions.me/schemas/friends",
"type": "object",
"properties": {
"friend": {
"properties": {
"id": {

"type": "number"

},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"dob": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
},
"gender": {
"type": "boolean"
},

"links": {
"type": "object",
"properties": {
"id": "string",
"relationships": "string",
"occasions": "string"
}
}
}
}
}
}

...but now I get the following error:
undefined method `each' for "string":String


Reply to this email directly or view it on GitHub
#259 (comment)
.

@wjdhamilton
Copy link
Author

Thanks, I did look at that but in my enthusiasm I decided to just crack on an write something. Won't be the first time!

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

2 participants