<commit_before>require 'rspec/core'
require 'colorize'
require_relative 'utils'

module ContractSchemaValidator
  class Contract
    include ContractVerifier::Utils
    include RSpec::Matchers
    include RSpec::Core::Pending

    def initialize(stub_root, service_port)
      @stub_root = stub_root
      @service_port = service_port
    end


    GET = 'GET'
    POST = 'POST'
    PUT = 'PUT'

    def validate(entry, context)
      begin
        request_file = entry['request']['file']
        if request_file.is_a?(Hash)
          request_file.each do |key, value|
            validate_consumer_schema entry, value
          end
        else
          validate_consumer_schema entry, request_file
        end

      rescue JSON::ParserError => e
        raise e
      end
    end

    def validate_consumer_schema(entry, schema_file)
      consumer_schema = schema_name schema_file
      unless file_present? consumer_schema
        raise SkipDeclaredInExample.new("Schema Undefined")
      end
      provider_schema = construct_path_for(entry['request']['url'])
      http_method = entry['request']['method']
      should verify_response(consumer_schema, provider_schema, http_method, @service_port)

      if http_method == POST || http_method == PUT
        should verify_request(consumer_schema, provider_schema, http_method, @service_port)
      end<commit_msg>#NoCard[Shruti/DD] Fail if schema file not found in contract verfication<commit_after>require 'rspec/core'
require 'colorize'
require_relative 'utils'

module ContractSchemaValidator
  class Contract
    include ContractVerifier::Utils
    include RSpec::Matchers
    include RSpec::Core::Pending

    def initialize(stub_root, service_port)
      @stub_root = stub_root
      @service_port = service_port
    end


    GET = 'GET'
    POST = 'POST'
    PUT = 'PUT'

    def validate(entry, context)
      begin
        request_file = entry['request']['file']
        if request_file.is_a?(Hash)
          request_file.each do |key, value|
            validate_consumer_schema entry, value
          end
        else
          validate_consumer_schema entry, request_file
        end

      rescue JSON::ParserError => e
        raise e
      end
    end

    def validate_consumer_schema(entry, schema_file)
      consumer_schema = schema_name schema_file
      unless file_present? consumer_schema
        fail("Schema file not found: #{schema_file}")
      end
      provider_schema = construct_path_for(entry['request']['url'])
      http_method = entry['request']['method']
      should verify_response(consumer_schema, provider_schema, http_method, @service_port)

      if http_method == POST || http_method == PUT
        should verify_request(consumer_schema, provider_schema, http_method, @service_port)
      end
{'fraction_non_alphanumeric': 0.07984246330110992, 'fraction_numerical': 0.0, 'mean_word_length': 3.072886297376093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3224873', 'n_tokens_mistral': 792, 'n_tokens_neox': 773, 'n_words': 192}