<commit_before>package http

import (
	"fmt"
	"github.com/viant/endly/testing/validator"
	"github.com/viant/toolbox"
	"github.com/viant/toolbox/data"
	"github.com/viant/toolbox/url"
)

//SendRequest represents a send http request.
type SendRequest struct {
	Options  []*toolbox.HttpOptions `description:"http client options: key value pairs, where key is one of the following: HTTP options:RequestTimeoutMs,TimeoutMs,KeepAliveTimeMs,TLSHandshakeTimeoutMs,ResponseHeaderTimeoutMs,MaxIdleConns"`
	Requests []*Request
	Expect   map[string]interface{} `description:"If specified it will validated response as actual"`
}

//Init initializes send request
func (s *SendRequest) Init() error {

	if s.Expect == nil {
		s.Expect = make(map[string]interface{})
	}
	if len(s.Requests) == 0 {
		return nil
	}
	if _, has := s.Expect["Responses"]; has {
		return nil
	}
	var hasExpectedResponse = false
	var emptyMap = make(map[string]interface{})
	var expectedResponses = make([]interface{}, 0)
	for _, request := range s.Requests {
		if request.Expect != nil {
			hasExpectedResponse = true
			expectedResponses = append(expectedResponses, request.Expect)
		} else {
			expectedResponses = append(expectedResponses, emptyMap)
		}
	}
	if hasExpectedResponse {
		s.Expect["Responses"] = expectedResponses
	}
	return nil
}

//NewSendRequestFromURL create new request from URL
func NewSendRequestFromURL(URL string) (*SendRequest, error) {
	resource := url.NewResource(URL)
	var request = &SendRequest{}
	return request, resource.Decode(request)
}<commit_msg>renamed service contract to contract<commit_after>package http

import (
	"fmt"
	"github.com/viant/endly/testing/validator"
	"github.com/viant/toolbox"
	"github.com/viant/toolbox/data"
	"github.com/viant/toolbox/url"
)

//SendRequest represents a send http request.
type SendRequest struct {
	Options  []*toolbox.HttpOptions `description:"http client options: key value pairs, where key is one of the following: HTTP options:RequestTimeoutMs,TimeoutMs,KeepAliveTimeMs,TLSHandshakeTimeoutMs,ResponseHeaderTimeoutMs,MaxIdleConns"`
	Requests []*Request
	Expect   map[string]interface{} `description:"If specified it will validated response as actual"`
}

//Init initializes send request
func (s *SendRequest) Init() error {

	if s.Expect == nil {
		s.Expect = make(map[string]interface{})
	}
	if len(s.Requests) == 0 {
		return nil
	}
	if _, has := s.Expect["Responses"]; has {
		return nil
	}
	var hasExpectedResponse = false
	var emptyMap = make(map[string]interface{})
	var expectedResponses = make([]interface{}, 0)
	for _, request := range s.Requests {
		if request.Expect != nil {
			hasExpectedResponse = true
			expectedResponses = append(expectedResponses, request.Expect)
		} else {
			expectedResponses = append(expectedResponses, emptyMap)
		}
	}
	if hasExpectedResponse {
		s.Expect["Responses"] = expectedResponses
	} else if len(s.Expect) == 0 {
		s.Expect = nil
	}
	return nil
}

//NewSendRequestFromURL create new request from URL
func NewSendRequestFromURL(URL string) (*SendRequest, error) {
	resource := url.NewResource(URL)
	var request = &SendRequest{}
	return request, resource.Decode(request)
}
{'fraction_non_alphanumeric': 0.1143128562381254, 'fraction_numerical': 0.0015832805573147563, 'mean_word_length': 5.075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1533391', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1001, 'n_words': 254}