class JSON::SchemaDsl::Entity

The basic entity type for json schemas.

This is mostly used in cases where you don't exactly know what type a property will have, for example if the property is an `anyOf` of different types.

Internally it is used as the superclass of all other types.

Public Class Methods

required_type() click to toggle source

nodoc

# File lib/json/schema_dsl/entity.rb, line 16
def required_type
  (Types::Bool | Types::Coercible::Array.of(Types::Coercible::String).default { [] })
end

Public Instance Methods

to_h() click to toggle source

@return [Hash<Symbol, Object>] Returns this entity as a hash and all children and

properties as simple values. This structure is used to render the eventual
schema by the renderer.

@see JSON::SchemaDsl::Rederer#initialize

Calls superclass method
# File lib/json/schema_dsl/entity.rb, line 41
def to_h
  super.transform_values do |v|
    is_array = v.is_a?(::Array)
    if (is_array ? v.first : v).respond_to?(:to_h)
      is_array ? v.map(&:to_h) : v.to_h
    else
      v
    end
  end
end