<commit_before>random = require 'otw/like/_/random'
type = require 'otw/like/_/type'
randexp = do () ->
  _randexp = require 'randexp'
  (pattern) -> new _randexp(pattern).gen()


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]<commit_msg>save the root schema on the generator instance<commit_after>random = require 'otw/like/_/random'
type = require 'otw/like/_/type'
randexp = do () ->
  _randexp = require 'randexp'
  (pattern) -> new _randexp(pattern).gen()


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

  return generator.generate()

class exports.Generator

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

  generate: (schema = null, depth = 0) ->

    schema = @root_schema unless schema

    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]
{'fraction_non_alphanumeric': 0.12101017186951947, 'fraction_numerical': 0.004209049456331112, 'mean_word_length': 2.8488529014844803, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1592351', 'n_tokens_mistral': 865, 'n_tokens_neox': 835, 'n_words': 272}