<commit_before>errors          = require '../errors'
{JsonSchema}   = require './json-schema'
{SchemaGenerator, SchemaProperties} = require('../utils/schema-generator')
jsonPointer = require 'json-pointer'

# Checks data, prepares validator and validates request or response headers against given expected headers or json schema
# @author <NAME> <<EMAIL>>
class HeadersJsonExample
  # Construct a HeadersValidator, checks data
  #@param [Object] real data to validate
  #@param [Object] expected expected data
  #@throw {MalformedDataError} when real is not a String or when no schema provided and expected is not a String
  #@throw {SchemaNotJsonParsableError} when given schema is not a json parsable string or valid json
  #@throw {NotEnoughDataError} when at least one of expected data and json schema is not given
  constructor: (@real, @expected) ->
    if typeof @real != 'object' 
      throw new errors.MalformedDataError "Real is not an Object"

    if typeof @expected != 'object'
      throw new errors.MalformedDataError "Expected is not an Object"
    
    try
      @expected = JSON.parse(JSON.stringify(@expected))
    catch error
      outError = new errors.MalformedDataError "Headers validator - Expected malformed:" + error.message
      outError['data'] = @expected
      throw outError

    try
      @real = @prepareHeaders JSON.parse(JSON.stringify(@real))
    catch error  
      outError = new errors.MalformedDataError "Headers validator - Real malformed:" + error.message
      outError['data'] = @real
      throw outError

    @schema = @getSchema @prepareHeaders @expected
    
    #headers to ignore their values  
    unless @schema == undefined
      unless @schema['properties'] == undefined
        ['date', 'expires'].forEach (header) =>  
          unless @schema['properties'][header] == undefined
            delete @schema['properties'][header]['enum']

    @validator = new JsonSchema @real, @schema

  #calls validation for given data
  validate: () ->
    @output = @validator.validate()
  
  
  @evaluateOutputToResults: (data) -> 
    results = []
    if data == null
      return results     
    
    #amanda to gavel converter
    if data.length > 0 # expects sanitized Tully pseudo amanda error
      indexes = [0..data.length - 1]
      indexes.forEach (index) ->
        item = data[index]
        console.error
        message =
          pointer: jsonPointer.compile item['property']
          severity: 'error'<commit_msg>added prepareHeaders call for @expected data<commit_after>errors          = require '../errors'
{JsonSchema}   = require './json-schema'
{SchemaGenerator, SchemaProperties} = require('../utils/schema-generator')
jsonPointer = require 'json-pointer'

# Checks data, prepares validator and validates request or response headers against given expected headers or json schema
# @author <NAME> <<EMAIL>>
class HeadersJsonExample
  # Construct a HeadersValidator, checks data
  #@param [Object] real data to validate
  #@param [Object] expected expected data
  #@throw {MalformedDataError} when real is not a String or when no schema provided and expected is not a String
  #@throw {SchemaNotJsonParsableError} when given schema is not a json parsable string or valid json
  #@throw {NotEnoughDataError} when at least one of expected data and json schema is not given
  constructor: (@real, @expected) ->
    if typeof @real != 'object' 
      throw new errors.MalformedDataError "Real is not an Object"

    if typeof @expected != 'object'
      throw new errors.MalformedDataError "Expected is not an Object"
    
    try
      @expected = JSON.parse(JSON.stringify(@expected))
    catch error
      outError = new errors.MalformedDataError "Headers validator - Expected malformed:" + error.message
      @expected = @prepareHeaders JSON.parse(JSON.stringify(@expected))
      throw outError

    try
      @real = @prepareHeaders JSON.parse(JSON.stringify(@real))
    catch error  
      outError = new errors.MalformedDataError "Headers validator - Real malformed:" + error.message
      outError['data'] = @real
      throw outError

    @schema = @getSchema @prepareHeaders @expected
    
    #headers to ignore their values  
    unless @schema == undefined
      unless @schema['properties'] == undefined
        ['date', 'expires'].forEach (header) =>  
          unless @schema['properties'][header] == undefined
            delete @schema['properties'][header]['enum']

    @validator = new JsonSchema @real, @schema

  #calls validation for given dataHeadersJsonExample
  validate: () ->
    @output = @validator.validate()
  
  
  @evaluateOutputToResults: (data) -> 
    results = []
    if data == null
      return results     
    
    #amanda to gavel converter
    if data.length > 0 # expects sanitized Tully pseudo amanda error
      indexes = [0..data.length - 1]
      indexes.forEach (index) ->
        item = data[index]
        console.error
        message =
          pointer: jsonPointer.compile item['property']
          severity: 'error'
{'fraction_non_alphanumeric': 0.09742063492063492, 'fraction_numerical': 0.0011904761904761906, 'mean_word_length': 3.190357439733998, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '1203744', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1318, 'n_words': 467}