json-schema-serializer 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +26 -3
- data/lib/json/schema/serializer.rb +3 -1
- data/lib/json/schema/serializer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34d2323a3916909a75c82c34fac5be56267ec91391737ccc56bccc44d28cc008
|
4
|
+
data.tar.gz: 754c7cfc61441a22cae20d198c943ba7688fa9f5b4898f4cb4458ccb9aa0501a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9b16d0c0cae997cba4db892b3ec9d36bebb05b36477ff5840c81728c595221e1fd27f939aac367934714cc82cf69bc25494f5e754f2984687320f5aafcbaab6
|
7
|
+
data.tar.gz: '082080bd9faf94c1cb444eef4874581e91009c385f1d9f7d2355864615bcfaa5fb80619b46e6eca99384bb0c22ee007ca604f2458e115897a31e734e93bde247'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.3.0
|
4
|
+
|
5
|
+
- add: resolver option to resolve `$ref`
|
6
|
+
- mod: regexp to string serialization
|
7
|
+
|
8
|
+
## 1.2.1
|
9
|
+
|
10
|
+
- add documentation link
|
11
|
+
|
12
|
+
## 1.2.0
|
13
|
+
|
14
|
+
- add: injector options
|
15
|
+
|
16
|
+
## 1.1.0
|
17
|
+
|
18
|
+
- add: "default" key handling
|
19
|
+
|
20
|
+
## 1.0.0
|
21
|
+
|
22
|
+
- feature not changed
|
23
|
+
|
3
24
|
## 0.1.0
|
4
25
|
|
5
26
|
- released
|
data/README.md
CHANGED
@@ -114,17 +114,17 @@ serializer_injected.serialize([1, 2, 3])
|
|
114
114
|
# => {"first"=>1, "count"=>3}
|
115
115
|
```
|
116
116
|
|
117
|
-
###
|
117
|
+
### `$ref` resolving
|
118
118
|
|
119
119
|
`JSON::Schema::Serializer` does not resolve `$ref` so use external resolver.
|
120
120
|
|
121
|
-
with `json_refs` gem example:
|
121
|
+
with `hana` and `json_refs` gem example:
|
122
122
|
|
123
123
|
```ruby
|
124
|
+
require "hana"
|
124
125
|
require "json_refs"
|
125
126
|
require "json/schema/serializer"
|
126
127
|
|
127
|
-
|
128
128
|
schema = {
|
129
129
|
"type" => "object",
|
130
130
|
"properties" => {
|
@@ -136,6 +136,29 @@ schema = {
|
|
136
136
|
serializer = JSON::Schema::Serializer.new(JsonRefs.(schema))
|
137
137
|
serializer.serialize({foo: 0, bar: "42"})
|
138
138
|
# => {"foo"=>0, "bar"=>42}
|
139
|
+
|
140
|
+
# resolver option also available
|
141
|
+
|
142
|
+
def walk(all, part)
|
143
|
+
if part.is_a?(Array)
|
144
|
+
part.map { |item| walk(all, item) }
|
145
|
+
elsif part.is_a?(Hash)
|
146
|
+
ref = part["$ref"] || part[:"$ref"]
|
147
|
+
if ref
|
148
|
+
Hana::Pointer.new(ref[1..-1]).eval(all)
|
149
|
+
else
|
150
|
+
part.map { |k, v| [k, walk(all, v)] }.to_h
|
151
|
+
end
|
152
|
+
else
|
153
|
+
part
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
serializer2 = JSON::Schema::Serializer.new(schema["properties"]["bar"], {
|
158
|
+
resolver: ->(schema) do
|
159
|
+
walk(all, JsonRefs.(schema))
|
160
|
+
end
|
161
|
+
})
|
139
162
|
```
|
140
163
|
|
141
164
|
## License
|
@@ -6,7 +6,7 @@ module JSON
|
|
6
6
|
class Schema
|
7
7
|
class Serializer
|
8
8
|
def initialize(obj, options = {})
|
9
|
-
@schema = obj
|
9
|
+
@schema = options && options[:resolver] ? options[:resolver].call(obj) : obj
|
10
10
|
@options = options
|
11
11
|
end
|
12
12
|
|
@@ -133,6 +133,8 @@ module JSON
|
|
133
133
|
else
|
134
134
|
obj.to_s
|
135
135
|
end
|
136
|
+
when Regexp
|
137
|
+
obj.inspect.gsub(%r`^/|/[a-z]*$`, '')
|
136
138
|
else
|
137
139
|
obj.to_s
|
138
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-schema-serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Narazaka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -181,7 +181,7 @@ metadata:
|
|
181
181
|
homepage_uri: https://github.com/Narazaka/json-schema-serializer
|
182
182
|
source_code_uri: https://github.com/Narazaka/json-schema-serializer.git
|
183
183
|
changelog_uri: https://github.com/Narazaka/json-schema-serializer/blob/master/CHANGELOG.md
|
184
|
-
documentation_uri: https://www.rubydoc.info/gems/json-schema-serializer/1.
|
184
|
+
documentation_uri: https://www.rubydoc.info/gems/json-schema-serializer/1.3.0
|
185
185
|
post_install_message:
|
186
186
|
rdoc_options: []
|
187
187
|
require_paths:
|