json-schema_builder 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json/schema_builder/entity.rb +2 -0
- data/lib/json/schema_builder/helpers.rb +18 -0
- data/lib/json/schema_builder/version.rb +1 -1
- data/spec/integration/ids_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -7
- data/spec/support/examples/ids.rb +12 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db809adc8a2ac574e1b54b042b62282ecda19423
|
4
|
+
data.tar.gz: 6c41e21a44a2e6d9d1fc67a470f1351469d28733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e863c5b0f63c05b29197583e1db2039de5cb62265ab69e75e62e7bfa95df0dfdf1c0dd9f24812b2170c43dcdff404e69b8f1e192960c6bce424d49adbfef5057
|
7
|
+
data.tar.gz: 01801525f6be2c93ef0be474b65ba5f9b9e8d3552de90bf293a7085608d1f2db3d26fcc10e72f90b1d25b923819ba88ab09fa05afd0a49e75d16089dc24571c6
|
@@ -2,6 +2,7 @@ require_relative 'dsl'
|
|
2
2
|
require_relative 'schema'
|
3
3
|
require_relative 'attribute'
|
4
4
|
require_relative 'validation'
|
5
|
+
require_relative 'helpers'
|
5
6
|
|
6
7
|
module JSON
|
7
8
|
module SchemaBuilder
|
@@ -9,6 +10,7 @@ module JSON
|
|
9
10
|
include DSL
|
10
11
|
include Attribute
|
11
12
|
include Validation
|
13
|
+
include Helpers
|
12
14
|
class_attribute :registered_type
|
13
15
|
attr_accessor :name, :parent, :children, :options
|
14
16
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module JSON
|
2
|
+
module SchemaBuilder
|
3
|
+
module Helpers
|
4
|
+
def id(name, opts = { }, &block)
|
5
|
+
nullable = opts.delete :null
|
6
|
+
entity name, opts do |child|
|
7
|
+
types = [
|
8
|
+
integer(minimum: 1),
|
9
|
+
string(pattern: '^[1-9]\d*$')
|
10
|
+
]
|
11
|
+
types << null if nullable
|
12
|
+
one_of types
|
13
|
+
child.eval_block &block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Examples::Ids, type: :integration do
|
4
|
+
it_behaves_like 'a builder' do
|
5
|
+
let(:expected_json) do
|
6
|
+
{
|
7
|
+
type: :object,
|
8
|
+
required: [:user_id],
|
9
|
+
properties: {
|
10
|
+
user_id: {
|
11
|
+
oneOf: [
|
12
|
+
{ type: 'integer', minimum: 1 },
|
13
|
+
{ type: 'string', pattern: '^[1-9]\d*$' }
|
14
|
+
]
|
15
|
+
},
|
16
|
+
optional_id: {
|
17
|
+
oneOf: [
|
18
|
+
{ type: 'integer', minimum: 1 },
|
19
|
+
{ type: 'string', pattern: '^[1-9]\d*$' },
|
20
|
+
{ type: 'null' }
|
21
|
+
]
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'pry'
|
2
|
-
require '
|
3
|
-
|
4
|
-
add_filter '/lib/json/schema_builder/rspec_helper'
|
5
|
-
add_filter '/spec'
|
6
|
-
end
|
7
|
-
|
8
|
-
SimpleCov.start
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
CodeClimate::TestReporter.start
|
9
4
|
|
10
5
|
%w(lib spec/support).each do |path|
|
11
6
|
Dir["./#{ path }/**/*.rb"].sort.each{ |file| require file }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-schema_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/json/schema_builder/configuration.rb
|
146
146
|
- lib/json/schema_builder/dsl.rb
|
147
147
|
- lib/json/schema_builder/entity.rb
|
148
|
+
- lib/json/schema_builder/helpers.rb
|
148
149
|
- lib/json/schema_builder/integer.rb
|
149
150
|
- lib/json/schema_builder/null.rb
|
150
151
|
- lib/json/schema_builder/number.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- spec/integration/array_definitions_spec.rb
|
161
162
|
- spec/integration/context_delegation_spec.rb
|
162
163
|
- spec/integration/entity_literals_spec.rb
|
164
|
+
- spec/integration/ids_spec.rb
|
163
165
|
- spec/integration/mixed_arrays_spec.rb
|
164
166
|
- spec/integration/mixed_objects_spec.rb
|
165
167
|
- spec/integration/object_definitions_spec.rb
|
@@ -176,6 +178,7 @@ files:
|
|
176
178
|
- spec/support/examples/array_definitions.rb
|
177
179
|
- spec/support/examples/context_delegation.rb
|
178
180
|
- spec/support/examples/entity_literals.rb
|
181
|
+
- spec/support/examples/ids.rb
|
179
182
|
- spec/support/examples/mixed_arrays.rb
|
180
183
|
- spec/support/examples/mixed_objects.rb
|
181
184
|
- spec/support/examples/object_definitions.rb
|
@@ -227,6 +230,7 @@ test_files:
|
|
227
230
|
- spec/integration/array_definitions_spec.rb
|
228
231
|
- spec/integration/context_delegation_spec.rb
|
229
232
|
- spec/integration/entity_literals_spec.rb
|
233
|
+
- spec/integration/ids_spec.rb
|
230
234
|
- spec/integration/mixed_arrays_spec.rb
|
231
235
|
- spec/integration/mixed_objects_spec.rb
|
232
236
|
- spec/integration/object_definitions_spec.rb
|
@@ -243,6 +247,7 @@ test_files:
|
|
243
247
|
- spec/support/examples/array_definitions.rb
|
244
248
|
- spec/support/examples/context_delegation.rb
|
245
249
|
- spec/support/examples/entity_literals.rb
|
250
|
+
- spec/support/examples/ids.rb
|
246
251
|
- spec/support/examples/mixed_arrays.rb
|
247
252
|
- spec/support/examples/mixed_objects.rb
|
248
253
|
- spec/support/examples/object_definitions.rb
|