jsonapi-grader 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/jsonapi-grader +7 -0
- data/lib/jsonapi/grader.rb +63 -0
- data/scenarii.json +38 -0
- data/scenarii/empty_collection.json +3 -0
- data/scenarii/null_data.json +3 -0
- data/scenarii/simple_resource.json +6 -0
- data/scenarii/simple_resource_attributes.json +10 -0
- data/scenarii/simple_resource_jsonapi_object.json +12 -0
- data/scenarii/simple_resource_meta.json +9 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bfad176fc40e0beeb8af7c6b493172270879598b
|
4
|
+
data.tar.gz: '08514b2293f96171636380fa129447552863bd59'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb55222d77f70bae46dc86b273f18229fb85b1aa9e854b293f62112c17b16b58c8062c7646248f3349f6ec2d421e487161108a8f9c0245eb6bc30016cbc49c51
|
7
|
+
data.tar.gz: 79135523a3199a5187e545fe8236dd537a8fdeb563cf0b0953a8b5bd788983968e44006869b779a33806fdd4b9f6f08763cb5257d0a7ae803818efd77c002432
|
data/bin/jsonapi-grader
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module JSONAPI
|
4
|
+
class Grader
|
5
|
+
def initialize(implementation_dir)
|
6
|
+
@implementation_dir = implementation_dir
|
7
|
+
scenarii_file = File.dirname(__FILE__) + '/../../scenarii.json'
|
8
|
+
@scenarii = JSON.parse(File.read(scenarii_file))
|
9
|
+
end
|
10
|
+
|
11
|
+
def grade
|
12
|
+
compliance = true
|
13
|
+
score = 0
|
14
|
+
max_score = 0
|
15
|
+
@scenarii.each do |scenario|
|
16
|
+
current_score = score_scenario(scenario)
|
17
|
+
compliance = false if scenario['required'] && current_score == 0
|
18
|
+
max_score += scenario['score']
|
19
|
+
score += current_score
|
20
|
+
end
|
21
|
+
|
22
|
+
STDERR.puts "Compliance: #{compliance}"
|
23
|
+
score_percent = (100.0 * score / max_score).round(2)
|
24
|
+
STDERR.puts "Score: #{score} / #{max_score} (#{score_percent}%)"
|
25
|
+
|
26
|
+
score
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def score_scenario(scenario)
|
32
|
+
document_file = File.dirname(__FILE__) + "/../../#{scenario['file']}"
|
33
|
+
reference_document = normalize(JSON.parse(File.read(document_file)))
|
34
|
+
implementation = "#{@implementation_dir}/#{scenario['name']}"
|
35
|
+
STDERR.print "Running scenario #{scenario['name']}... "
|
36
|
+
$stderr.flush
|
37
|
+
unless File.exists?(implementation)
|
38
|
+
STDERR.puts "not implemented"
|
39
|
+
return 0
|
40
|
+
end
|
41
|
+
|
42
|
+
actual_document = normalize(JSON.parse(`#{implementation}`))
|
43
|
+
if reference_document == actual_document
|
44
|
+
STDERR.puts "passed"
|
45
|
+
return scenario['score']
|
46
|
+
else
|
47
|
+
STDERR.puts "failed"
|
48
|
+
STDERR.puts "Expected: #{reference_document}"
|
49
|
+
STDERR.puts "Got: #{actual_document}"
|
50
|
+
$stderr.flush
|
51
|
+
return 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def normalize(document)
|
56
|
+
return document unless document.key?('included')
|
57
|
+
|
58
|
+
document['included'].sort do |a, b|
|
59
|
+
[a['type'], a['id']] <=> [b['type'], b['id']]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/scenarii.json
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"name": "null_data",
|
4
|
+
"file": "scenarii/null_data.json",
|
5
|
+
"score": 100,
|
6
|
+
"required": true
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name": "empty_collection",
|
10
|
+
"file": "scenarii/empty_collection.json",
|
11
|
+
"score": 100,
|
12
|
+
"required": true
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"name": "simple_resource",
|
16
|
+
"file": "scenarii/simple_resource.json",
|
17
|
+
"score": 100,
|
18
|
+
"required": true
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "simple_resource_attributes",
|
22
|
+
"file": "scenarii/simple_resource_attributes.json",
|
23
|
+
"score": 100,
|
24
|
+
"required": true
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "simple_resource_meta",
|
28
|
+
"file": "scenarii/simple_resource_meta.json",
|
29
|
+
"score": 10,
|
30
|
+
"required": false
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"name": "simple_resource_jsonapi_object",
|
34
|
+
"file": "scenarii/simple_resource_jsonapi_object.json",
|
35
|
+
"score": 10,
|
36
|
+
"required": false
|
37
|
+
}
|
38
|
+
]
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsonapi-grader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Hosseini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ensure compliance of your JSON API library.
|
14
|
+
email: lucas.hosseini@gmail.com
|
15
|
+
executables:
|
16
|
+
- jsonapi-grader
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- "./scenarii/empty_collection.json"
|
21
|
+
- "./scenarii/null_data.json"
|
22
|
+
- "./scenarii/simple_resource.json"
|
23
|
+
- "./scenarii/simple_resource_attributes.json"
|
24
|
+
- "./scenarii/simple_resource_jsonapi_object.json"
|
25
|
+
- "./scenarii/simple_resource_meta.json"
|
26
|
+
- bin/jsonapi-grader
|
27
|
+
- lib/jsonapi/grader.rb
|
28
|
+
- scenarii.json
|
29
|
+
homepage: https://github.com/beauby/jsonapi-grader
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.6.12
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Grade jsonapi.org implementations.
|
53
|
+
test_files: []
|