Skip to content
This repository was archived by the owner on Nov 13, 2020. It is now read-only.

Commit a62ed95

Browse files
committed
Add some initial information to the schema.
1 parent f37f3a0 commit a62ed95

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

lib/json/api.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ def self.parse(source, opts={})
1515
end
1616

1717
def self.validate(source, opts={})
18-
json = JSON.parse(source) if source.kind_of?(String)
19-
20-
JSON::Validator.validate!('lib/json/api/schema.json', json)
18+
source = JSON.parse(source) if source.kind_of?(String)
19+
JSON::Validator.validate!('lib/json/api/schema.json', source)
2120
end
2221
end
2322
end

lib/json/api/schema.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
{
2-
"$schema": "http://json-schema.org/draft-04/schema#"
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "JSON API Schema",
4+
"description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
5+
"type": "object",
6+
"patternProperties": {
7+
"^(?!href$)(?!links$)(?!id$)(?!meta)(?!linked)": {
8+
"type": "array",
9+
"items": {
10+
"type": "object"
11+
}
12+
}
13+
},
14+
"properties": {
15+
"meta": {
16+
"type": "object"
17+
},
18+
"linked": {
19+
"type": "object"
20+
}
21+
}
322
}

test/schema_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'json/api'
2+
3+
class SchemaTest < MiniTest::Unit::TestCase
4+
def test_homepage_id_style
5+
json = <<-JSON
6+
{
7+
"posts": [{
8+
"id": "1",
9+
"title": "Rails is Omakase",
10+
"links": {
11+
"author": "9",
12+
"comments": [ "5", "12", "17", "20" ]
13+
}
14+
}]
15+
}
16+
JSON
17+
18+
assert JSON::Api.parse(json), "failed to parse"
19+
end
20+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy