Module: JSON::SchemaBuilder::Helpers

Included in:
Entity
Defined in:
lib/json/schema_builder/helpers.rb

Instance Method Summary collapse

Instance Method Details

#id(name, opts = { }, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/json/schema_builder/helpers.rb', line 4

def id(name, opts = { }, &block)
  nullable = opts.delete :null
  entity name, opts do |child|
    types = [
      integer(minimum: 1),
      string(pattern: '^[1-9]\d*$')
    ]
    types << null if nullable
    one_of types
    child.eval_block &block
  end
end