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

Add coverage for JSON Schema V4 #89

Merged
merged 1 commit into from Apr 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
141 changes: 141 additions & 0 deletions spec/json_matchers/match_json_schema_spec.rb
Expand Up @@ -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

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]

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" },
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
"type": { "type": "string" },
"attributes": {
"$ref": "#/definitions/attributes",
}
}
})
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"
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}]
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
})

expect(json).not_to match_json_schema(posts_index)
end

it "can reference a schema relatively" do
create(:schema, name: "post", json: {
"$schema": "https://json-schema.org/draft-04/schema#",
"id": "file:/post.json#",
"type": "object",
"required": [
"id",
"type",
"attributes"
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
],
"properties": {
"id": { "type": "string" },
"type": { "type": "string" },
"attributes": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"user": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": { "type": "string" }
}
}
}
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
})
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"
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
],
"definitions": {
"posts": {
"type": "array",
"items": {
"$ref": "file:/post.json#"
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
},
"properties": {
"data": {
"$ref": "#/definitions/posts"
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
})

json = build(:response, {
"data": [{
"id": "1",
"type": "Post",
"attributes": {
"id": "1",
"name": "The Post's Name",
"user": {
"id": "1"
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}
seanpdoyle marked this conversation as resolved.
Show resolved Hide resolved
}]
})

expect(json).to match_json_schema(posts_index)
end

context "when passed a Hash" do
it "validates that the schema matches" do
schema = create(:schema, :location)
Expand Down