json-api-vanilla 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/Rakefile +1 -1
- data/json-api-vanilla.gemspec +1 -1
- data/lib/json-api-vanilla/parser.rb +15 -1
- data/lib/json-api-vanilla/version.rb +2 -2
- data/lib/json-api-vanilla.rb +1 -1
- data/spec/json-api-vanilla/diff_spec.rb +30 -1
- data/spec/spec_helper.rb +1 -1
- metadata +6 -9
- data/ContributorAgreement.txt +0 -17
- data/contributors/TadasTamosauskas.txt +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f596658618531c4fcf2aed7ff39a9656b5050739abb19a7cf893ab0b5bcadc74
|
4
|
+
data.tar.gz: a2c6b0fc63242520d2910127eb2235e80f4c28c5b198872dc2805e71c5ec2bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b620c77f17f81ca2a271a0a30771e2ec6937c45efe2940e5a2c6a9f4b4616b3fbe4dba7f79f9254c0b5ef6e61f1df4507ef8162b0a2495af2e0dfab89f8ebfdf
|
7
|
+
data.tar.gz: 65777666d5db295d3cc31993a8f80f0a69d651abcde67d3b209a987b0adbe21bd789303d8f0fa2e49277672e420157cd73392aecca78cc57f257691bd8387b38
|
data/LICENSE.txt
CHANGED
data/Makefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
install:
|
3
3
|
gem build json-api-vanilla.gemspec && gem install ./json-api-vanilla-*.gem
|
4
4
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
|
4
4
|
require 'bundler'
|
data/json-api-vanilla.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
3
|
require 'json-api-vanilla/version'
|
4
4
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
module JSON::Api; end
|
@@ -72,6 +72,8 @@ module JSON::Api::Vanilla
|
|
72
72
|
obj = objects[[o_hash['type'], o_hash['id']]]
|
73
73
|
if o_hash['relationships']
|
74
74
|
o_hash['relationships'].each do |key, value|
|
75
|
+
naive_validate_relationship_object(value)
|
76
|
+
|
75
77
|
if value['data']
|
76
78
|
data = value['data']
|
77
79
|
if data.is_a?(Array)
|
@@ -198,6 +200,18 @@ module JSON::Api::Vanilla
|
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
203
|
+
# Naïvely validate a relationship object.
|
204
|
+
# @param hash [Hash] json:api document as a hash
|
205
|
+
# @raise [InvalidRootStructure] raised if the document doesn't have data, errors nor meta objects
|
206
|
+
# at its root.
|
207
|
+
def self.naive_validate_relationship_object(hash)
|
208
|
+
root_keys = %i(data meta links)
|
209
|
+
present_structures = root_keys & hash.keys.map(&:to_sym)
|
210
|
+
if present_structures.empty?
|
211
|
+
raise InvalidRootStructure.new("JSON:API relationship must contain at least one of these objects: #{root_keys.join(', ')}")
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
201
215
|
class Document
|
202
216
|
# @return [Object, Array<Object>] the content of the JSON API data.
|
203
217
|
attr_reader :data
|
@@ -1,8 +1,8 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
module JSON
|
3
3
|
module Api
|
4
4
|
module Vanilla
|
5
|
-
VERSION = '1.0.
|
5
|
+
VERSION = '1.0.3'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/json-api-vanilla.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
require 'json-api-vanilla/parser'
|
3
3
|
require 'json-api-vanilla/version'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe JSON::Api::Vanilla do
|
@@ -94,6 +94,35 @@ describe JSON::Api::Vanilla do
|
|
94
94
|
end.to raise_error(JSON::Api::Vanilla::InvalidRootStructure)
|
95
95
|
end
|
96
96
|
|
97
|
+
it "should raise an error if the document contains an unrecognized element" do
|
98
|
+
json = <<-JSON
|
99
|
+
{
|
100
|
+
"type": "object",
|
101
|
+
"id": "123",
|
102
|
+
"attributes": {},
|
103
|
+
"foo": "bar"
|
104
|
+
}
|
105
|
+
JSON
|
106
|
+
expect do
|
107
|
+
JSON::Api::Vanilla.parse(json)
|
108
|
+
end.to raise_error(JSON::Api::Vanilla::InvalidRootStructure)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should raise an error if a relationship object does not have one of the required fields" do
|
112
|
+
json = <<-JSON
|
113
|
+
{
|
114
|
+
"data": {
|
115
|
+
"type": "cycle",
|
116
|
+
"id": "1",
|
117
|
+
"relationships": { "cycle": { "type": "cycle", "id": "2" } }
|
118
|
+
}
|
119
|
+
}
|
120
|
+
JSON
|
121
|
+
expect do
|
122
|
+
JSON::Api::Vanilla.parse(json)
|
123
|
+
end.to raise_error(JSON::Api::Vanilla::InvalidRootStructure)
|
124
|
+
end
|
125
|
+
|
97
126
|
it "should not raise any errors if the document contains root elements as symbols" do
|
98
127
|
expect do
|
99
128
|
JSON::Api::Vanilla.naive_validate(data: { id: 1, type: 'mvp' })
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright © Trainline Limited, 2016. All rights reserved. See LICENSE.txt in the project root for license information.
|
1
|
+
# Copyright © Trainline Limited, 2016, Thaddée Tyl, 2016-2022. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
2
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
3
|
|
4
4
|
require 'rubygems'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-api-vanilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thaddée Tyl
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Given a JSON API string, we parse it and return a document that can be
|
14
14
|
browsed — as if the objects defined in the file were plain old Ruby objects.
|
@@ -20,14 +20,12 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- ".github/workflows/ruby.yml"
|
22
22
|
- ".gitignore"
|
23
|
-
- ContributorAgreement.txt
|
24
23
|
- Gemfile
|
25
24
|
- LICENSE.txt
|
26
25
|
- Makefile
|
27
26
|
- NOTICE.txt
|
28
27
|
- README.md
|
29
28
|
- Rakefile
|
30
|
-
- contributors/TadasTamosauskas.txt
|
31
29
|
- json-api-vanilla.gemspec
|
32
30
|
- lib/json-api-vanilla.rb
|
33
31
|
- lib/json-api-vanilla/parser.rb
|
@@ -39,7 +37,7 @@ homepage: http://github.com/trainline/json-api-vanilla
|
|
39
37
|
licenses:
|
40
38
|
- Apache-2.0
|
41
39
|
metadata: {}
|
42
|
-
post_install_message:
|
40
|
+
post_install_message:
|
43
41
|
rdoc_options: []
|
44
42
|
require_paths:
|
45
43
|
- lib
|
@@ -54,9 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
52
|
- !ruby/object:Gem::Version
|
55
53
|
version: '0'
|
56
54
|
requirements: []
|
57
|
-
|
58
|
-
|
59
|
-
signing_key:
|
55
|
+
rubygems_version: 3.1.2
|
56
|
+
signing_key:
|
60
57
|
specification_version: 4
|
61
58
|
summary: Deserialize JSON API formats into vanilla Ruby objects.
|
62
59
|
test_files: []
|
data/ContributorAgreement.txt
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
Contributor Agreement
|
2
|
-
Thank you for your interest in Trainline. In order to clarify the intellectual property license granted with code contributions from any person or entity, Trainline.com Limited ("Trainline") requires a Contributor License Agreement on file that has been signed by each contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Trainline and its users; it does not change your rights to use your own contributions for any other purpose.
|
3
|
-
Please send confirmation that you accept the terms set out below to osscontribs@thetrainline.com. Please read the terms carefully before accepting and keep a copy for your records.
|
4
|
-
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Trainline. Except for the license granted herein to Trainline and recipients of software distributed by Trainline, You reserve all right, title, and interest in and to Your Contributions.
|
5
|
-
|
6
|
-
1. Definitions.
|
7
|
-
"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Trainline. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty per cent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
8
|
-
"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Trainline for inclusion in, or documentation of, any of the products owned or managed by Trainline (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Trainline or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Trainline for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
|
9
|
-
2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Trainline and to recipients of software distributed by Trainline a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
|
10
|
-
3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Trainline and to recipients of software distributed by Trainline a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
|
11
|
-
4. You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to Trainline, or that your employer has executed a separate agreement with Trainline.
|
12
|
-
5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
|
13
|
-
6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
-
7. Should You wish to submit work that is not Your original creation, You may submit it to Trainline separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".
|
15
|
-
8. You agree to notify Trainline of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
|
16
|
-
|
17
|
-
Please sign: __________________________________ Date: ________________
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Contributor Agreement
|
2
|
-
Thank you for your interest in Trainline. In order to clarify the intellectual property license granted with code contributions from any person or entity, Trainline.com Limited ("Trainline") requires a Contributor License Agreement on file that has been signed by each contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of Trainline and its users; it does not change your rights to use your own contributions for any other purpose.
|
3
|
-
Please send confirmation that you accept the terms set out below to osscontribs@thetrainline.com. Please read the terms carefully before accepting and keep a copy for your records.
|
4
|
-
You accept and agree to the following terms and conditions for Your present and future Contributions submitted to Trainline. Except for the license granted herein to Trainline and recipients of software distributed by Trainline, You reserve all right, title, and interest in and to Your Contributions.
|
5
|
-
|
6
|
-
1. Definitions.
|
7
|
-
"You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with Trainline. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty per cent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
8
|
-
"Contribution" shall mean any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Trainline for inclusion in, or documentation of, any of the products owned or managed by Trainline (the "Work"). For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to Trainline or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Trainline for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."
|
9
|
-
2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Trainline and to recipients of software distributed by Trainline a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
|
10
|
-
3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Trainline and to recipients of software distributed by Trainline a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.
|
11
|
-
4. You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to Trainline, or that your employer has executed a separate agreement with Trainline.
|
12
|
-
5. You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
|
13
|
-
6. You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
14
|
-
7. Should You wish to submit work that is not Your original creation, You may submit it to Trainline separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which you are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".
|
15
|
-
8. You agree to notify Trainline of any facts or circumstances of which you become aware that would make these representations inaccurate in any respect.
|
16
|
-
|
17
|
-
Please sign: Tadas Tamošauskas
|
18
|
-
Date: 2016-10-06
|