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
Add coverage for JSON Schema V4 #89
Conversation
2b08d1f
to
225e8c0
Compare
"attributes" | ||
], | ||
"properties": { | ||
"id": { "type": "number" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanpdoyle The type of id should be "string". The test fails if we change the type from number to string.
@@ -59,6 +59,147 @@ | |||
expect(json).to match_json_schema("api/v1/schema") | |||
end | |||
|
|||
it "supports invalidating the referenced schema when using local references" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [81/80]
|
||
json = build(:response, { | ||
"data": [{ | ||
"id": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert this id attribute as a string, i.e. "id": "1". Keep the id inside the attributes as a number. The test will fail now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will pass: it "Fails properly in local refs in referenced schema" do
create(:schema, name: "post", json: {
"$schema": "https://json-schema.org/draft-04/schema#",
"id": "file:/post.json#",
"definitions": {
"attributes": {
"type": "object",
"required": [
"id",
"name",
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
}
}
},
"type": "object",
"required": [
"id",
"type",
"attributes"
],
"properties": {
"id": { "type": "string" },
"type": { "type": "string" },
"attributes": {
# "$ref": "#/definitions/attributes"
"type": "object",
"required": [
"id",
"name",
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
}
}
}
})
posts_index = create(:schema, name: "posts/index", json: {
"$schema": "https://json-schema.org/draft-04/schema#",
"id": "file:/posts/index.json#",
"type": "object",
"required": [
"data"
],
"definitions": {
"posts": {
"type": "array",
"items": {
"$ref": "file:/post.json#"
}
}
},
"properties": {
"data": {
"$ref": "#/definitions/posts"
}
}
})
json = build(:response, {
"data": [{
"id": "1",
"type": "Post",
"attributes": {
"id": 1,
"name": "The Post's Name"
}
}]
})
expect(json).not_to match_json_schema(posts_index)
end But this test will fail: it "Fails properly in local refs in referenced schema" do
create(:schema, name: "post", json: {
"$schema": "https://json-schema.org/draft-04/schema#",
"id": "file:/post.json#",
"definitions": {
"attributes": {
"type": "object",
"required": [
"id",
"name",
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
}
}
},
"type": "object",
"required": [
"id",
"type",
"attributes"
],
"properties": {
"id": { "type": "string" },
"type": { "type": "string" },
"attributes": {
"$ref": "#/definitions/attributes"
# "type": "object",
# "required": [
# "id",
# "name",
# ],
# "properties": {
# "id": { "type": "string" },
# "name": { "type": "string" }
# }
}
}
})
posts_index = create(:schema, name: "posts/index", json: {
"$schema": "https://json-schema.org/draft-04/schema#",
"id": "file:/posts/index.json#",
"type": "object",
"required": [
"data"
],
"definitions": {
"posts": {
"type": "array",
"items": {
"$ref": "file:/post.json#"
}
}
},
"properties": {
"data": {
"$ref": "#/definitions/posts"
}
}
})
json = build(:response, {
"data": [{
"id": "1",
"type": "Post",
"attributes": {
"id": 1,
"name": "The Post's Name"
}
}]
})
expect(json).not_to match_json_schema(posts_index)
end Check out the difference in the commented out codes in |
@seanpdoyle any updates for this PR? |
Closes [#88]. Closes [#90]. Add tests from Issue #90 When the `"id"` key is specified as a `"number"` in both attribute and property definitions, then specified as a `"string"` value in the payload, the matcher will raise and the test will pass. After rebasing off `master` after [`3b66b4d`][3b66b4d] was merged, [the tests that were once failing][tests] are now passing. [#88]: #88 [#90]: #90 [3b66b4d]: 3b66b4d [tests]: #89 (comment)
Closes #88.
Closes #90.
Add tests from Issue #90
When the
"id"
key is specified as a"number"
in both attribute andproperty definitions, then specified as a
"string"
value in thepayload, the matcher will raise and the test will pass.
After rebasing off
master
after3b66b4d
was merged, thetests that were once failing are now passing.