json_schema_tools 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/schema_tools/modules/hash.rb +9 -1
- data/lib/schema_tools/modules/read.rb +6 -0
- data/lib/schema_tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGQwMzVlNmIwYjkxYjhkY2UxNGVjMTdhMGNmMDRhMjJkNmU3MmUwZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yjc3N2MyM2NjMDYzOGU2YTRlM2ZlNTkyMmNmOTU4ZGI3MmYyOTU4ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Zjk2ZDQwNDNiYzM5NTRkYWY2NzcyYTMwNWQzZGI3YTc4ZjkzNTQxNTJhMjAw
|
10
|
+
MDA2YWQxN2QwNmU0NzZmZDJhMzI2ZDBlNzQ2ZDE4OWI1YTE4YjA2YjFlNzll
|
11
|
+
OTcxNWE3NjkwYWU4ZWRjY2ZkYzQwODIxMjcxOWEzOWQwMTUyNGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2Y3NmZjZmY0Y2Q4NGVmNTRmYWMyMGQ4NzMyN2E4OTBmZDUyNmE3MTllM2Q3
|
14
|
+
MzUyYmIzMWQwNjI5ODk2ZjFjOWY3OWZkYjdiNmQyNWY1ZjRjMmEwNjI0Njc0
|
15
|
+
N2ViNWUyMGY0YWM5YzY3YzUzYmZhZmI3NDlmYTc3YThhYjEyZTg=
|
@@ -28,7 +28,8 @@ module SchemaTools
|
|
28
28
|
# @param [Hash{Symbol=>Mixed}] opts additional options
|
29
29
|
# @options opts [String|Symbol] :class_name used as hash key. Should be
|
30
30
|
# a lowercase underscored name and it MUST have an existing schema file.
|
31
|
-
# Use it to override the default, which is obj.class.name
|
31
|
+
# Use it to override the default, which is obj.class.name. Only used for
|
32
|
+
# top-level object NOT nested objects
|
32
33
|
# @options opts [Array<String>] :fields to return. If not set all schema
|
33
34
|
# properties are used.
|
34
35
|
# @options opts [String] :path of the schema files overriding global one
|
@@ -71,8 +72,10 @@ module SchemaTools
|
|
71
72
|
schema['properties'].each do |field, prop|
|
72
73
|
next if fields && !fields.include?(field)
|
73
74
|
if prop['type'] == 'array'
|
75
|
+
opts.delete(:class_name)
|
74
76
|
data[field] = parse_list(obj, field, prop, opts)
|
75
77
|
elsif prop['type'] == 'object' # a singular related object
|
78
|
+
opts.delete(:class_name)
|
76
79
|
data[field] = parse_object(obj, field, prop, opts)
|
77
80
|
else # a simple field is only added if the object knows it
|
78
81
|
data[field] = obj.send(field) if obj.respond_to?(field)
|
@@ -142,6 +145,11 @@ module SchemaTools
|
|
142
145
|
if obj.respond_to?( field ) && rel_obj = obj.send( field )
|
143
146
|
if prop['properties'] && prop['properties']['$ref']
|
144
147
|
res = from_schema(rel_obj, opts)
|
148
|
+
elsif prop['oneOf']
|
149
|
+
# auto-detects which schema to use depending on the rel_object type
|
150
|
+
# Simpler than detecting the object type or $ref to use inside the
|
151
|
+
# oneOf array
|
152
|
+
res = from_schema(rel_obj, opts)
|
145
153
|
else
|
146
154
|
# NO recursion directly get values from related object. Does
|
147
155
|
# NOT allow deeper nesting so you MUST define an own schema to be save
|
@@ -42,6 +42,12 @@ module SchemaTools
|
|
42
42
|
elsif path_or_schema.is_a?(::String) || path_or_schema.nil?
|
43
43
|
path = path_or_schema
|
44
44
|
file_path = File.join(path || SchemaTools.schema_path, "#{schema_name}.json")
|
45
|
+
unless File.exist?(file_path)
|
46
|
+
# check if file exists else try to find first real path in sub-dirs
|
47
|
+
recursive_search = Dir.glob( File.join(SchemaTools.schema_path, '**/*', "#{schema_name}.json"))[0]
|
48
|
+
# use only if we found something, else keep path which will throw error on file.open later
|
49
|
+
file_path = recursive_search || file_path
|
50
|
+
end
|
45
51
|
else
|
46
52
|
raise ArgumentError, 'Second parameter must be a path or a schema!'
|
47
53
|
end
|
data/lib/schema_tools/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Leciejewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|