class Inspec::Schema::Primitives::SchemaType

Use this class to quickly add/use object types to/in a definition block

def all_depends

Recursively acquire all depends for this schema. Return them sorted by name
def all_depends
  result = @depends
  # Fetch all from children
  @depends.each do |nested_type|
    # Yes, converting back to set here does some duplicate sorting.
    # But here, performance really isn't our concern.
    result += Set.new(nested_type.all_depends)
  end
  # Return the results as a sorted array
  Array(result).sort_by(&:name)
end

def body

Use to actually define the ref!
Produce this schema types generated body.
def body
  @body.merge({
      "description" => @description,
      "title" => @name,
  }).compact
end

def initialize(name, body, dependencies, description = nil)

def initialize(name, body, dependencies, description = nil)
  # Validate the schema
  Primitives.validate_schema(body)
  # The title of the type
  @name = name
  # The body of the type
  @body = body
  # What SchemaType[]s it depends on. In essence, any thing that you .ref in the body
  @depends = Set.new(dependencies)
  # The description of the type
  @description = description
end

def ref

Yields this type as a json schema ref
def ref
  { "$ref" => "#/definitions/#{ref_name}" }
end

def ref_name

Formats this to have a JSON pointer compatible title
def ref_name
  @name.gsub(/\s+/, "_")
end