         # minimum set to 1, not 0, on purpose
       howManyMoreProperties = random 'integer', randomOptions
       for i in [0..howManyMoreProperties]
-        o[random 'string', {minimum: 0, maximum: 10}] = @generate schema.additionalProperties, method, depth+1
+        o[random 'string', {minimum: 0, maximum: 10}] = @generate schema.additionalProperties, depth+1
 
     else if schema.additionalProperties isnt false
-      o[random 'string', {minimum: 0, maximum: 10}] = @generate {type: 'any'}, method, depth+1
+      o[random 'string', {minimum: 0, maximum: 10}] = @generate {type: 'any'}, depth+1
 
     return o
 
 
   # type = any
-  any: (schema, method = 'all', depth = 0) ->
+  any: (schema, depth = 0) ->
     types = ['string', 'number', 'integer', 'boolean', 'object', 'null']
     randomOptions =
       minimum: 0
       maximum: types.length-1
     typeIndex = random 'integer', randomOptions
-    @generate {type: types[typeIndex]}, method, depth + 1
+    @generate {type: types[typeIndex]}, depth + 1
 
 
   # type = []
-  oneOf: (schema, method = 'all', depth = 0) ->
+  oneOf: (schema, depth = 0) ->
     return 0  unless schema.type.length # treat as 'any'
     randomOptions =
       minimum: 0
       maximum: schema.type.length-1
     typeIndex = random 'integer', randomOptions
-    @generate schema.type[typeIndex], method, depth + 1
+    @generate schema.type[typeIndex], depth + 1



  # type = boolean
  boolean: (schema, method = 'all', depth = 0) ->
    random 'boolean'


  # type = number / integer
  number: (schema, method = 'all', depth = 0) ->
    @integer schema, method, depth

  integer: (schema, method = 'all', depth = 0) ->
    minimum = schema.exclusiveMinimum + 1  if schema.exclusiveMinimum
    minimum ?= schema.minimum
    maximum = schema.exclusiveMaximum - 1  if schema.exclusiveMaximum


module.exports = exports = (schema, method = 'all') ->
  generator = new exports.Generator
    method: method

  return generator.generate schema

class exports.Generator

  constructor: (options) ->
    @method = options.method

  generate: (schema, depth = 0) ->

    return schema  unless type(schema) is 'object'

    return @enum schema, depth  if schema.enum

    switch schema.type
      when 'string', 'number', 'integer', 'boolean', 'array', 'object', 'null'
        return @[schema.type] schema, depth
      else
        if type(schema.type) is 'array'
          return @oneOf schema, depth
        # FIXME what if type(schema.type) = 'object' and _.size(schema.type) > 0 ?
        if schema.type is 'any' or type(schema.type) is 'undefined' or (type(schema.type) is 'object' and _.size(schema.type) is 0)
          return @any schema, depth
        # FIXME what type is this?
        console.log schema.type
        throw "what type is this ?"


  # enum
  'enum': (schema, depth = 0) ->
    randomOptions =
      minimum: 0
      maximum: schema.enum.length - 1
    randomIndex = random 'integer', randomOptions
    enumValue = schema.enum[randomIndex]
    @generate enumValue, depth + 1


  # type = null
