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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmNjZDJjNDRjZTMyNjFjM2U0ZjFhMTRkMTJhZGNkNWVjYmVhZmU2MQ==
4
+ ZmU2MzJlYzY5MGM2NGIxMDkyNWIwY2NiZWFiNGVkODY2NjdhNzkxYg==
5
5
  data.tar.gz: !binary |-
6
- NzI1OWY0OTU1ZDJmMDVmOTMyMTgzZTQ5ZjE3YjRmNDFjMzJmYzBjYg==
6
+ NzY3NGYyOGY4MTU1ODQwMmYyMjhlZDRkZjQxNDA0Y2M2ZWI2ZDVhNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTFmODcwMmM2MDBmZmU0YWZlYjIyODMyNjlkM2EyZWY1NTliZWI1YjQwYTU0
10
- NGNlYTI1MmE1Y2FlMWY5ZGIwOGQwNzI2OTc5OTNlYTliMDIxMTZkZGQ2ODlj
11
- N2NiNjFlNWQ0ZGVmM2E3M2M1NTZiM2U1NzM2ZjNmMmE2MGQ1MjM=
9
+ MjZmMWZhODZmM2FlNDgyODQ0NmU4NmI1OGQzZTNjNDk5ZDRmNmEzYTU4MjY0
10
+ NWYzNmE1NTg0YzgzZTViOWFhNjc1NjcwMWQ1NTkyZDQ1NmRkZjRkYTgxOTg5
11
+ NTAwNzc0YzkxNmQwZjY2YzU0MDg0MGJkMmFjYWY2NWViNWE2OGU=
12
12
  data.tar.gz: !binary |-
13
- MmMzNGU5NjkxYWQ1NzFkYzkzODcxNzI2NzY3ZTAwODE0OGY1YWUyOTY3ZTE1
14
- ZGNjMGFhNGQ5YjU0YzNhZDJjYWIxNWUwN2M2NTNjMDZiMDI4ZmUwMTI0Njc1
15
- ZDcyMzkzOTQ5Y2MzNzUwOTViODNkYjE5ZDIzNjY1NTJhNmFjMmI=
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
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module SchemaTools
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -7,8 +7,8 @@
7
7
  "person": {
8
8
  "type" : "object",
9
9
  "oneOf" : [
10
- { "$ref" : "./client.json.json#properties"},
11
- { "$ref" : "./contact.json.json#properties"}
10
+ { "$ref" : "./client.json#"},
11
+ { "$ref" : "./contact.json#"}
12
12
  ]
13
13
  }
14
14
  }
@@ -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.0
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