json_schema_tools 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +8 -0
- data/lib/schema_tools/schema.rb +7 -1
- data/lib/schema_tools/version.rb +1 -1
- data/spec/fixtures/one_of_definition.json +2 -2
- data/spec/schema_tools/reader_spec.rb +7 -0
- data/spec/schema_tools/schema_spec.rb +32 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmU2MzJlYzY5MGM2NGIxMDkyNWIwY2NiZWFiNGVkODY2NjdhNzkxYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzY3NGYyOGY4MTU1ODQwMmYyMjhlZDRkZjQxNDA0Y2M2ZWI2ZDVhNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjZmMWZhODZmM2FlNDgyODQ0NmU4NmI1OGQzZTNjNDk5ZDRmNmEzYTU4MjY0
|
10
|
+
NWYzNmE1NTg0YzgzZTViOWFhNjc1NjcwMWQ1NTkyZDQ1NmRkZjRkYTgxOTg5
|
11
|
+
NTAwNzc0YzkxNmQwZjY2YzU0MDg0MGJkMmFjYWY2NWViNWE2OGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjRiZDRlNTRiNTI4MDNhZmJlZmE4MDU3ZjA4Y2ZjMmQ3MjIyMDVhMTlhZDFk
|
14
|
+
YWRjNDkzZDg0Njc1ZDdhMGE2NWI5YzQ0YWNkMWM3NjRjMjkzYjdkYWM2ZjFj
|
15
|
+
ODIxYWIxYTVlY2RiYzYyYmJlMWVlM2E3ZWI5NDJkYTY3NDYzZDI=
|
data/README.md
CHANGED
@@ -92,6 +92,14 @@ reader.read :client, 'from/path'
|
|
92
92
|
reader.registry
|
93
93
|
```
|
94
94
|
|
95
|
+
Get a schema as plain ruby hash with all $refs de-referenced
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
SchemaTools::Reader.read_all
|
99
|
+
client_schema = SchemaTools::Reader.registry[:client]
|
100
|
+
schema_hash = client_schema.to_h
|
101
|
+
```
|
102
|
+
|
95
103
|
## Object to JSON - from Schema
|
96
104
|
|
97
105
|
As you probably know such is done e.g in rails via object.as_json. While using
|
data/lib/schema_tools/schema.rb
CHANGED
@@ -79,7 +79,9 @@ module SchemaTools
|
|
79
79
|
@absolute_dir || SchemaTools.schema_path
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
def to_h
|
83
|
+
@hash
|
84
|
+
end
|
83
85
|
|
84
86
|
protected
|
85
87
|
|
@@ -130,6 +132,10 @@ module SchemaTools
|
|
130
132
|
resolve_reference schema
|
131
133
|
elsif v.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
132
134
|
resolve_refs v
|
135
|
+
elsif v.is_a?(Array)
|
136
|
+
v.each do |i|
|
137
|
+
resolve_refs(i) if i.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
138
|
+
end
|
133
139
|
end
|
134
140
|
end
|
135
141
|
|
data/lib/schema_tools/version.rb
CHANGED
@@ -14,6 +14,13 @@ describe SchemaTools::Reader do
|
|
14
14
|
person_schema.should be
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'reads returns schemas' do
|
18
|
+
SchemaTools::Reader.read_all
|
19
|
+
client_schema = SchemaTools::Reader.registry[:client]
|
20
|
+
expect(client_schema.to_h['name']).to eq 'client'
|
21
|
+
end
|
22
|
+
|
23
|
+
|
17
24
|
end
|
18
25
|
|
19
26
|
context '.read' do
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SchemaTools::Schema do
|
4
|
+
|
5
|
+
context '.initialize' do
|
6
|
+
after :each do
|
7
|
+
SchemaTools::Reader.registry_reset
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'reads all schemas' do
|
11
|
+
schema = SchemaTools::Schema.new("#{SchemaTools.schema_path}/client.json")
|
12
|
+
expect(schema['name']).to eq 'client'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context '.to_h' do
|
18
|
+
after :each do
|
19
|
+
SchemaTools::Reader.registry_reset
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns hash with de-referenced $refs' do
|
23
|
+
schema = SchemaTools::Schema.new("#{SchemaTools.schema_path}/one_of_definition.json")
|
24
|
+
hash = schema.to_h
|
25
|
+
first = hash['properties']['person']['oneOf'][0]
|
26
|
+
expect(first['title']).to eq 'client'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Leciejewski
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- spec/schema_tools/modules/attributes_spec.rb
|
115
115
|
- spec/schema_tools/reader_spec.rb
|
116
116
|
- spec/schema_tools/ref_resolver_spec.rb
|
117
|
+
- spec/schema_tools/schema_spec.rb
|
117
118
|
- spec/spec_helper.rb
|
118
119
|
- spec/test_helpers.rb
|
119
120
|
homepage: https://github.com/salesking/json_schema_tools
|