parametric 0.2.18 → 0.2.19

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: 403aac3495b3e90bc32cf01c0229b83497d37413fb43b6180c3dafd0a9ec36b9
4
- data.tar.gz: a8396d8ab3831e7c93d1643f96562ff0d5fe1ddaa8794dfe7ed8993bd4732cd5
3
+ metadata.gz: 98676c8edebba19bd1adff020f5eadf9dce07e44f89125be4f0451d6bdee50cf
4
+ data.tar.gz: 5a5d0ecded864e5185d2b1d1cafe5eeb2307d92cf52c4111e7dd85ebe65c0321
5
5
  SHA512:
6
- metadata.gz: dbd04349edf7e8f4777ef7c681ec8f16d2cf570d915088fae04942760415d9fd88123741b68957839b21d7145d97b83b6cf6911fce5f0e2db806d34a304e1a0d
7
- data.tar.gz: 9851e0d8f4e5e48d38870027c8a987fbf65f264a8c9dfaafe74080ff463e3783267f605eae09ce65b1f43547a27935ae532fd75120d60823fd24e8bf09bd0c4d
6
+ metadata.gz: 1a3b81c816a02516450bdeb70ddb5b804741481ec0084167f31cdddcef4c3734f25b0d69da022048d9889c7b47a462cd821bf3a4cef07d719aff9b57293e10ef
7
+ data.tar.gz: 5a2cd8dd4d68cd896901d744f656fca3385f6d3763bc05d62dbd1b6c53362a32092781e7bd57e439b27c6e0071d1179a0355372778d33b9c96f893e6fd4e07d3
@@ -76,6 +76,8 @@ module Parametric
76
76
  meta = field.meta_data.dup
77
77
  sc = meta.delete(:schema)
78
78
  meta[:structure] = sc.schema.structure if sc
79
+ one_of = meta.delete(:one_of)
80
+ meta[:one_of] = one_of.values.map(&:structure) if one_of
79
81
  obj[field.key] = meta
80
82
  end
81
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parametric
4
- VERSION = '0.2.18'
4
+ VERSION = '0.2.19'
5
5
  end
data/spec/schema_spec.rb CHANGED
@@ -307,6 +307,29 @@ describe Parametric::Schema do
307
307
  expect(result.valid?).to be true
308
308
  expect(result.output).to eq({ type: 'user', sub: { name: 'Joe', age: 30 } })
309
309
  end
310
+
311
+ specify '#structure' do
312
+ user_or_company = Parametric::TaggedOneOf.new do |sub|
313
+ sub.on('user', user_schema)
314
+ sub.on('company', company_schema)
315
+ end
316
+
317
+ schema = described_class.new do |sc, _|
318
+ sc.field(:type).type(:string)
319
+ sc.field(:sub).type(:object).tagged_one_of(user_or_company.index_by(:type))
320
+ end
321
+
322
+ structure = schema.structure
323
+ structure.dig(:sub).tap do |sub|
324
+ expect(sub[:type]).to eq :object
325
+ expect(sub[:one_of][0][:name][:type]).to eq :string
326
+ expect(sub[:one_of][0][:name][:required]).to be true
327
+ expect(sub[:one_of][0][:name][:present]).to be true
328
+ expect(sub[:one_of][0][:age][:type]).to eq :integer
329
+
330
+ expect(sub[:one_of][1][:company_code][:type]).to eq :string
331
+ end
332
+ end
310
333
  end
311
334
 
312
335
  describe "#ignore" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parametric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis