attributor 6.1 → 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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a27077cb0a67b6ab8fdde19c88a993ba648c6deb38d5a83766df49b7199338d
4
- data.tar.gz: 99bf9996744d757817fd167fa510b462fab6ee1dd3b52992594d06768966bd53
3
+ metadata.gz: 82e7c7fa061464ff15336123c9809e743e2111da05c7155b2e20f6ece94196e3
4
+ data.tar.gz: 0cfdbaf2baa22792c3ccbaceffed7950131d9e2b4a7d67d5723e080e40e13873
5
5
  SHA512:
6
- metadata.gz: e91ad1a7759be0e56c66f53bafbe6d22f1a2ce724fc777ade2649987d6bf19d184eb0fc5f43d00dcbf2310bbae72359199f34d25c38aa65cc69f38cc28d33a55
7
- data.tar.gz: 947764564827d2d05e967f60ccc100d42eedf219fddab8ffff56bb8f61c0264c67e9bdd77d3a3585b99d80e5e54f22ef2a6e3424c3ba83549df0932874b0c0af
6
+ metadata.gz: ccc3cc9e5ca7ae70b69501831559e616e5a631b7fe6b67b59c099399d7f1ee53479f657c5d951e0f20b84eb12e0a19643f8a83060e50684925652c25b5ec4527
7
+ data.tar.gz: e01d93ff03633e0a3361236fa2a76aa450880bd2f0594cbc2348da0daf9ecc7ec1c821d69fd4c020609a53e1ec4cac9886d84e9b4864c4def46f6a0c02174e69
data/CHANGELOG.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Attributor Changelog
2
2
 
3
3
  ## next
4
- - added support for enum's out of values in json_schema generation
4
+
5
+ ## 6.2 (5/11/2022)
6
+ - Added .to_hash for Model/Struct, which returns a symbolized key hash (without recursing). This allows to splat instances of Model/Structs into functions that have keyword arguments.
5
7
 
6
8
  ## 6.1 (1/7/2022)
7
9
  - added support for enum's out of values in json_schema generation
@@ -179,6 +179,11 @@ module Attributor
179
179
  ensure
180
180
  @dumping = false
181
181
  end
182
+
183
+ # This allows the splatting of these instances into method calls (top level hash conversion only)
184
+ def to_hash
185
+ @contents
186
+ end
182
187
  end
183
188
 
184
189
  # Override the generic way to get a value from an instance (models need to call the method)
@@ -13,10 +13,20 @@ module Attributor
13
13
  def self.example(_context = nil, options: {})
14
14
  'An Object'
15
15
  end
16
-
16
+
17
+ # Not really used (we override as_json_schema to represent this as an Any Type),
18
+ # but if it _were_ used, this would be accurate.
17
19
  def self.json_schema_type
18
- :object #FIXME: not sure this is the most appropriate, since an Attributor::Object can be anything
20
+ :object
19
21
  end
20
22
 
23
+ # Represents Object as an OpenAPI Any Type.
24
+ #
25
+ # @see https://swagger.io/docs/specification/data-models/data-types/#any
26
+ def self.as_json_schema(**kwargs)
27
+ schema = super(**kwargs)
28
+ schema.delete(:type)
29
+ schema
30
+ end
21
31
  end
22
32
  end
@@ -1,3 +1,3 @@
1
1
  module Attributor
2
- VERSION = '6.1'.freeze
2
+ VERSION = '6.2'.freeze
3
3
  end
@@ -0,0 +1,2 @@
1
+ class UntypedObject < Attributor::Object
2
+ end
@@ -523,4 +523,26 @@ describe Attributor::Model do
523
523
  expect(example.dump).to eq({})
524
524
  end
525
525
  end
526
+
527
+ context '#to_hash' do
528
+ let(:model_type) do
529
+ Class.new(Attributor::Model) do
530
+ attributes do
531
+ attribute :name, String
532
+ attribute :subkey do
533
+ attribute :id, Integer
534
+ end
535
+ end
536
+ end
537
+ end
538
+
539
+ subject { model_type.new(name: 'Praxis', subkey: { id: 1 }).to_hash }
540
+ it 'returns the top keys as a hash' do
541
+ expect(subject.keys).to eq([:name, :subkey])
542
+ end
543
+ it 'does not recurse down' do
544
+ expect(subject[:subkey]).to be_kind_of Attributor::Struct
545
+ end
546
+ end
547
+
526
548
  end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+
3
+ describe Attributor::Object do
4
+ context 'JSON Schema representation' do
5
+ subject { UntypedObject.as_json_schema }
6
+ it 'is an Any Type' do
7
+ # "A schema without a type matches any data type – numbers, strings, objects, and so on."
8
+ # c.f. https://swagger.io/docs/specification/data-models/data-types/#any
9
+ expect(subject).not_to have_key(:type)
10
+ # but we still preserve Ruby type name, if anyone is curious
11
+ expect(subject[:"x-type_name"]).to eq("UntypedObject")
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attributor
3
3
  version: !ruby/object:Gem::Version
4
- version: '6.1'
4
+ version: '6.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
8
8
  - Dane Jensen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-02-07 00:00:00.000000000 Z
12
+ date: 2022-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -291,7 +291,7 @@ dependencies:
291
291
  - - ">="
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
- description:
294
+ description:
295
295
  email:
296
296
  - blanquer@gmail.com
297
297
  - dane.jensen@gmail.com
@@ -361,6 +361,7 @@ files:
361
361
  - spec/support/hashes.rb
362
362
  - spec/support/integers.rb
363
363
  - spec/support/models.rb
364
+ - spec/support/objects.rb
364
365
  - spec/support/polymorphics.rb
365
366
  - spec/type_spec.rb
366
367
  - spec/types/bigdecimal_spec.rb
@@ -377,6 +378,7 @@ files:
377
378
  - spec/types/ids_spec.rb
378
379
  - spec/types/integer_spec.rb
379
380
  - spec/types/model_spec.rb
381
+ - spec/types/object_spec.rb
380
382
  - spec/types/polymorphic_spec.rb
381
383
  - spec/types/regexp_spec.rb
382
384
  - spec/types/string_spec.rb
@@ -390,7 +392,7 @@ homepage: https://github.com/rightscale/attributor
390
392
  licenses:
391
393
  - MIT
392
394
  metadata: {}
393
- post_install_message:
395
+ post_install_message:
394
396
  rdoc_options: []
395
397
  require_paths:
396
398
  - lib
@@ -406,7 +408,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
406
408
  version: '0'
407
409
  requirements: []
408
410
  rubygems_version: 3.1.2
409
- signing_key:
411
+ signing_key:
410
412
  specification_version: 4
411
413
  summary: A powerful attribute and type management library for Ruby
412
414
  test_files:
@@ -422,6 +424,7 @@ test_files:
422
424
  - spec/support/hashes.rb
423
425
  - spec/support/integers.rb
424
426
  - spec/support/models.rb
427
+ - spec/support/objects.rb
425
428
  - spec/support/polymorphics.rb
426
429
  - spec/type_spec.rb
427
430
  - spec/types/bigdecimal_spec.rb
@@ -438,6 +441,7 @@ test_files:
438
441
  - spec/types/ids_spec.rb
439
442
  - spec/types/integer_spec.rb
440
443
  - spec/types/model_spec.rb
444
+ - spec/types/object_spec.rb
441
445
  - spec/types/polymorphic_spec.rb
442
446
  - spec/types/regexp_spec.rb
443
447
  - spec/types/string_spec.rb