json_schema_tools 0.6.1 → 0.6.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDI3MjBjMGQ2NjA2YjJkN2Y1ZjFiN2NjZTM2NTMzMTJlYmEwNzE5Mg==
4
+ MzRiOTM3ZmEzMGQzMThiMmE0NjJiZThmY2JiNmM2OTBjMmVhYzU3OA==
5
5
  data.tar.gz: !binary |-
6
- YTk0Mjg5NTU4MjlkNzA5YzJlYzExNDAyNWVlNDI0MDM5ZmQ1YzI3Nw==
6
+ ZTNjNGQ5ZThkMGQ1ODc0NjFlNTE5OWRiYWRiY2Q2NmYwZjJkOTAzZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWZlOGQyODY4MTg0ZDBkMGYzZGFhMDlmZWMyOTE0ZTA1OTY2YTk4NWUxNTA1
10
- OTIzYWYxYWEwYzJkMjI5YjY0NmM2MjIzNzczNzViMGZiODgzMTcyZTIwNTNi
11
- OWM3YTdmNWRkMTRkYzBkYWJlZjMyNzJhOGY1YTA4ZjJiNmMwOTI=
9
+ MDIwMmFlNGMzMWMyNTE3NmM5MjJmOWYzY2Q4MjA4NGM1NWJlNmEzNWFiM2Uw
10
+ MjIwZTk3ZDdkMmJlODMxOGM2ZmFkMTA0ZWU5ZTAwZDk0OTQ0OTVlMmE2MDI2
11
+ MzdkY2UxMTE0MGEyZjdjNjAyZTc3ZjFlNTdiNDgzMWNiMjUwYjU=
12
12
  data.tar.gz: !binary |-
13
- ZDJiZGQ2NWQ5YmIxN2FjMTVmMTVhOGQxYWNhOWU5NDM5NDkxYjY2OWE3ZjJl
14
- YTNkMmQ2ODFjNzI2NGU4M2U0YmIyODgzNTBlZGU4MDZlMDJmY2RhZWE3MzJk
15
- MGFmZGVlNDlkMmQ1ZjA1YmEzYTAwOTAzMzYxZDdiZjgzY2NlNzI=
13
+ ZDlhNGY2ZGM1MDM2ZjliMjk5YjY3NzVjNDEzNjYxZGY0M2EzNzFmMTQ4Yjkx
14
+ NmVkNjVmOWNmN2QwYjc3ZmFmNjAwNzVhN2UzYzM4NjY4NWYwZTA2NzVjZGEx
15
+ YjFhN2QxZmU1MzA0Y2VjODFhZDM0MGI2NmY4ZDU0ZjljNDRhNjk=
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Changelog JSON Schema Tools
2
2
 
3
+ ##2015-04
4
+
5
+ * use schema definition in nested items array Thanks @VidurMalik
6
+
3
7
  ##2015-03
4
8
 
5
- * allow $refs to include plain schema file name
9
+ * allow $refs to include plain schema file name without #suffix
6
10
 
7
11
  ##2015-01
8
12
 
@@ -155,7 +155,10 @@ module SchemaTools
155
155
  if SCHEMA_BASE_TYPES.include?(prop['items']['type'])
156
156
  res = rel_objects
157
157
  elsif prop['items']['type'] == 'object'
158
- rel_objects.each { |rel_obj| res << from_schema(rel_obj, opts) }
158
+ rel_objects.each do |rel_obj|
159
+ opts[:schema] = prop['items']
160
+ res << from_schema(rel_obj, opts)
161
+ end
159
162
  end
160
163
  end
161
164
 
@@ -191,4 +194,4 @@ module SchemaTools
191
194
 
192
195
  end
193
196
  end
194
- end
197
+ end
@@ -1,3 +1,3 @@
1
1
  module SchemaTools
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
  end
@@ -28,6 +28,11 @@ class Conversion
28
28
  attr_accessor :from, :to
29
29
  end
30
30
 
31
+ class AnotherAddress
32
+ include SchemaTools::Modules::Attributes
33
+ has_schema_attrs 'address'
34
+ end
35
+
31
36
 
32
37
  describe SchemaTools::Hash do
33
38
 
@@ -100,6 +105,62 @@ describe SchemaTools::Hash do
100
105
 
101
106
  end
102
107
 
108
+ context 'with nested values referencing a schema that is different from the class name' do
109
+ let(:client){Client.new}
110
+
111
+ it 'has an empty array if values are missing' do
112
+ hash = SchemaTools::Hash.from_schema(client)
113
+ hash['addresses'].should == []
114
+ end
115
+
116
+ it 'has nil if nested object is missing' do
117
+ hash = SchemaTools::Hash.from_schema(client)
118
+ hash['work_address'].should be_nil
119
+ end
120
+
121
+ it 'has nested array values' do
122
+ a1 = AnotherAddress.new
123
+ a1.city = 'Cologne'
124
+ a1.zip = 50733
125
+ client.addresses = [a1]
126
+ hash = SchemaTools::Hash.from_schema(client)
127
+ hash['addresses'].should == [{"id" => nil,
128
+ "city"=>"Cologne",
129
+ "address1" => nil,
130
+ "zip"=>"50733",
131
+ "country" => nil,
132
+ "address_type" => nil}]
133
+ end
134
+
135
+ it 'has nested array values without root' do
136
+ a1 = AnotherAddress.new
137
+ a1.city = 'Cologne'
138
+ a1.zip = 50733
139
+ client.addresses = [a1]
140
+ hash = SchemaTools::Hash.from_schema(client, exclude_root: true)
141
+ hash['addresses'].should == [{"id" => nil,
142
+ "city"=>"Cologne",
143
+ "address1" => nil,
144
+ "zip"=>"50733",
145
+ "country" => nil,
146
+ "address_type" => nil}]
147
+ end
148
+
149
+ it 'has nested object value' do
150
+ a1 = AnotherAddress.new
151
+ a1.city = 'Cologne'
152
+ a1.zip = 50733
153
+ client.work_address = a1
154
+ hash = SchemaTools::Hash.from_schema(client)
155
+ hash['work_address'].should == {"id" => nil,
156
+ "city"=>"Cologne",
157
+ "address1" => nil,
158
+ "zip"=>"50733",
159
+ "country" => nil,
160
+ "address_type" => nil}
161
+ end
162
+ end
163
+
103
164
  context 'with nested values referencing a schema' do
104
165
 
105
166
  let(:client){Client.new}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Leciejewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json