     return schema  unless type(schema) is 'object'
 
     return @enum schema, depth  if schema.enum
+
+    if schema.$ref
+      return @ref schema.$ref, depth
 
     switch schema.type
       when 'string', 'number', 'integer', 'boolean', 'array', 'object', 'null'

      maximum: schema.type.length-1
    typeIndex = random 'integer', randomOptions
    @generate schema.type[typeIndex], depth + 1

  # type = array
  array: (schema, depth = 0) ->
    o = []

    if type(schema.items) is 'object' and schema.items.$ref
      result = @ref schema.items.$ref, depth
      return [result]

    if type(schema.items) is 'array' and schema.items.length
      for itemSchema in schema.items
        o.push @generate itemSchema, depth + 1
