json-schema-serializer 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62a4161f9050de4df1b222a1ebd2b5556ea8362759f7dd26b0d03f54511659d0
4
- data.tar.gz: df64164f07b39ff544be501d94f157ae5c23f35123bdc5ac6eb79c10531f990c
3
+ metadata.gz: 4b4c5d9d360e8b71d59ffaf2dbaef3a19cb782acdbb4c97548188f4c3339d654
4
+ data.tar.gz: 180e413608d626170441274fa43c82a20cf62d78a5509cc1cee6b8ade65dbeae
5
5
  SHA512:
6
- metadata.gz: a6e9a5725b9a66ffb70b36cb3cdd7460319ec1d650a4e5524f8d0fd72ec375e4ebd0904080d9f30a3a2f00ba3ef904541ef1245730ec6d9ac528d9ca571624b0
7
- data.tar.gz: 1eb6b5e3554c72b45bebd546f1afbc3a47b40d1d60bef2c61fd8f0eafb4a5e4358b706f7c627b5fab4025dd127b8b4d237d9ef72351d1947f03a284c0279c1b0
6
+ metadata.gz: 6b5e545a90241344d73da7d4a015ba83e0d96ec71df27f98652f755018c2c241b612cdbbcbdcf0b3fc5b10a447e493047a035cdf93c770f42214a41e90935b7b
7
+ data.tar.gz: 8c875c4c2681df2ef05ae8bde119c6cd1a9cc6621e667616e8df935acfe34c2a4c459cf648730aa9e9439240d805382ff9d8033f2edecd804e8a697def9877e5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.0
4
+
5
+ - add: "additionalProperties" support
6
+
3
7
  ## 1.3.0
4
8
 
5
9
  - add: resolver option to resolve `$ref`
data/README.md CHANGED
@@ -114,6 +114,12 @@ serializer_injected.serialize([1, 2, 3])
114
114
  # => {"first"=>1, "count"=>3}
115
115
  ```
116
116
 
117
+ ### "additionalProperties"
118
+
119
+ "additionalProperties" is allowed but must be a schema object. (not boolean)
120
+
121
+ If "additionalProperties" does not exists, this serializer works as `{ additionalProperties": false }`.
122
+
117
123
  ### `$ref` resolving
118
124
 
119
125
  `JSON::Schema::Serializer` does not resolve `$ref` so use external resolver.
@@ -163,10 +163,22 @@ module JSON
163
163
  obj.nil? ? [] : obj.map { |item| walk(items_schema, item, true, options) }
164
164
  when "object"
165
165
  properties_schema = try_hash(schema, :properties)
166
+ additional_properties_schema = try_hash(schema, :additionalProperties)
166
167
  required_schema = Set.new(try_hash(schema, :required)&.map(&:to_s))
167
- properties_schema.map do |name, property_schema|
168
+ ret = properties_schema.map do |name, property_schema|
168
169
  [name.to_s, walk(property_schema, try_hash(obj, name), required_schema.include?(name.to_s), options)]
169
170
  end.to_h
171
+ if additional_properties_schema
172
+ not_additional_keys = Set.new(properties_schema.keys.map(&:to_s))
173
+ additional_keys = obj.keys.reject { |key| not_additional_keys.include?(key.to_s) }
174
+ ret.merge(
175
+ additional_keys.map do |name|
176
+ [name.to_s, walk(additional_properties_schema, try_hash(obj, name), false, options)]
177
+ end.to_h
178
+ )
179
+ else
180
+ ret
181
+ end
170
182
  end
171
183
  end
172
184
 
@@ -1,7 +1,7 @@
1
1
  module Json
2
2
  module Schema
3
3
  module Serializer
4
- VERSION = "1.3.1".freeze
4
+ VERSION = "1.4.0".freeze
5
5
  end
6
6
  end
7
7
  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.3.1
4
+ version: 1.4.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-30 00:00:00.000000000 Z
11
+ date: 2019-12-01 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.3.1
184
+ documentation_uri: https://www.rubydoc.info/gems/json-schema-serializer/1.4.0
185
185
  post_install_message:
186
186
  rdoc_options: []
187
187
  require_paths: