jbuilder-schema 2.6.3 → 2.6.4

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: 3ece2220807094bf6da825da24512a4dabd0ce985aa935a16e9247c0e5d4c70e
4
- data.tar.gz: f04dc67915f12690c7eca1efc2357f915351584061a6b0ece6598326606b0bbf
3
+ metadata.gz: d3b0ea78dca91b88897944b81769f35798117c891702c585c6197a18c141736a
4
+ data.tar.gz: 668c8e606e9a52392114fb94dfe73f333ab7831dba7fd21c602fbcad1ee37c0c
5
5
  SHA512:
6
- metadata.gz: eb350992a61f92fbaee952b0167369caf119fd2d3f2695f647e1d774974e461e01e6a9cd1b7d5d4da2c19abe0658f8a74b601bedeff7d4e78de8365a6c61b02b
7
- data.tar.gz: c9582ca4c80ba75106468c8b806cc443be3ee54a630afaa786524d249a4ef8d8bc5eeaef1f1beebb2b00c32e739cfe23be7734695cfff04a51f95de326a7fbd4
6
+ metadata.gz: 7277d58ee426c5635adbbae4b1f8e2b68fc0b16aa6ab42653d1e7dc7ebb62c3f13e3917e767b57ee723f82d52043064db415690e18207820fa6036584b9b4faa
7
+ data.tar.gz: 1c8b45fcf22dd2a219fd22c3483c4d68fa05d0f519fa66eb5593a1476fe73e98bc2a0cb3f07635933890bb297d0183d5451c152d1e10a567b3797ad1deaff9f6
@@ -63,7 +63,7 @@ class Jbuilder::Schema
63
63
 
64
64
  # Rails 7.1 calls `to_s` on our `target!` (the return value from our templates).
65
65
  # To get around that and let our inner Hash through, we add this override.
66
- # `unwrap_target!` is added for backwardscompatibility so we get the inner Hash on Rails < 7.1.
66
+ # `unwrap_target!` is added for backwards compatibility so we get the inner Hash on Rails < 7.1.
67
67
  def to_s
68
68
  @object
69
69
  end
@@ -257,7 +257,6 @@ class Jbuilder::Schema
257
257
  when :array
258
258
  _schema(key, value, within_array: true)
259
259
  when :object
260
- value = value.attributes if value.is_a?(::ActiveRecord::Base)
261
260
  {
262
261
  type: type,
263
262
  properties: _set_properties(key, value)
@@ -267,12 +266,6 @@ class Jbuilder::Schema
267
266
  end
268
267
  end
269
268
 
270
- def _set_properties(key, value)
271
- value.each_with_object({}) do |(attr_name, attr_value), properties|
272
- properties[attr_name] = _schema("#{key}.#{attr_name}", attr_value)
273
- end
274
- end
275
-
276
269
  def _primitive_type(value)
277
270
  case value
278
271
  when ::Hash, ::Struct, ::OpenStruct, ::ActiveRecord::Base then :object
@@ -286,11 +279,22 @@ class Jbuilder::Schema
286
279
  end
287
280
 
288
281
  def _set_value(key, value)
282
+ value = _value(value)
289
283
  value = _schema(key, value) unless value.is_a?(::Hash) && (value.key?(:type) || value.key?(:allOf)) # rubocop:disable Style/UnlessLogicalOperators
290
284
  _set_description(key, value)
291
285
  super
292
286
  end
293
287
 
288
+ def _set_properties(key, value)
289
+ _value(value).each_with_object({}) do |(attr_name, attr_value), properties|
290
+ properties[attr_name] = _schema("#{key}.#{attr_name}", attr_value)
291
+ end
292
+ end
293
+
294
+ def _value(value)
295
+ value.respond_to?(:attributes) ? value.attributes : value
296
+ end
297
+
294
298
  def _required!(keys)
295
299
  presence_validated_attributes = @configuration.object&.class.try(:validators).to_a.flat_map { _1.attributes if _1.is_a?(::ActiveRecord::Validations::PresenceValidator) }
296
300
  keys & [_key(:id), *presence_validated_attributes.flat_map { [_key(_1), _key("#{_1}_id")] }]
@@ -1,4 +1,4 @@
1
1
  # We can't use the standard `Jbuilder::Schema::VERSION =` because
2
2
  # `Jbuilder` isn't a regular module namespace, but a class …which also loads Active Support.
3
3
  # So we use trickery, and assign the proper version once `jbuilder/schema.rb` is loaded.
4
- JBUILDER_SCHEMA_VERSION = "2.6.3"
4
+ JBUILDER_SCHEMA_VERSION = "2.6.4"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbuilder-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Sidorov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-10 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder