parametric 0.2.18 → 0.2.19
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 +4 -4
- data/lib/parametric/schema.rb +2 -0
- data/lib/parametric/version.rb +1 -1
- data/spec/schema_spec.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98676c8edebba19bd1adff020f5eadf9dce07e44f89125be4f0451d6bdee50cf
|
4
|
+
data.tar.gz: 5a5d0ecded864e5185d2b1d1cafe5eeb2307d92cf52c4111e7dd85ebe65c0321
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a3b81c816a02516450bdeb70ddb5b804741481ec0084167f31cdddcef4c3734f25b0d69da022048d9889c7b47a462cd821bf3a4cef07d719aff9b57293e10ef
|
7
|
+
data.tar.gz: 5a2cd8dd4d68cd896901d744f656fca3385f6d3763bc05d62dbd1b6c53362a32092781e7bd57e439b27c6e0071d1179a0355372778d33b9c96f893e6fd4e07d3
|
data/lib/parametric/schema.rb
CHANGED
data/lib/parametric/version.rb
CHANGED
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
|