Class: JSON::Schema::String

Inherits:
Leaf
  • Object
show all
Defined in:
lib/json/schema/string.rb

Overview

The JSON::Schema::String class represents a string value in a JSON schema. It is a subclass of JSON::Schema::Leaf and provides methods that can act as constraints.

Instance Method Summary collapse

Methods inherited from Leaf

#const, #default, #description, #enum, #initialize, #required, #required?, #to_json

Constructor Details

This class inherits a constructor from JSON::Schema::Leaf

Instance Method Details

#min(i) ⇒ JSON::Schema::String

Constrain the string to a minimum length

Parameters:

  • i (Integer)

    The minimum length

Returns:



14
15
16
# File 'lib/json/schema/string.rb', line 14

def min(i)
  tap { @minimum = i }
end

#max(i) ⇒ JSON::Schema::String

Constrain the string to a maximum length

Parameters:

  • i (Integer)

    The maximum length

Returns:



22
23
24
# File 'lib/json/schema/string.rb', line 22

def max(i)
  tap { @maximum = i }
end

#to_hObject



26
27
28
29
30
31
32
# File 'lib/json/schema/string.rb', line 26

def to_h
  super.merge!({
    type: "string",
    minLength: @minimum,
    maxLength: @maximum
  }).compact
end