<commit_before>package validators

import (
	"fmt"
	"sort"
	"strings"

	"bitbucket.org/cihangirsavas/gene/schema"
	"bitbucket.org/cihangirsavas/gene/stringext"
)

func GenerateValidator(p *schema.Schema) string {
	validators := make([]string, 0)
	// schemaName := p.Title
	schemaFirstChar := stringext.ToLowerFirst(p.Title)

	for key, property := range p.Properties {
		switch property.Type {
		case "string":
			if property.MinLength != 0 {
				validator := fmt.Sprintf("validator.MinLength(%s.%s, %d)", schemaFirstChar, key, property.MinLength)
				validators = append(validators, validator)
			}

			if property.MaxLength != 0 {
				validator := fmt.Sprintf("validator.MaxLength(%s.%s, %d)", schemaFirstChar, key, property.MaxLength)
				validators = append(validators, validator)
			}

			if property.Pattern != "" {
				validator := fmt.Sprintf("validator.Pattern(%s.%s, \"%s\")", schemaFirstChar, key, property.Pattern)
				validators = append(validators, validator)
			}

			if len(property.Enum) > 0 {
				validator := fmt.Sprintf("validator.OneOf(%s.%s, []string{\"%s\"})", schemaFirstChar, key, strings.Join(property.Enum, "\",\""))
				validators = append(validators, validator)
			}

			switch property.Format {
			case "date-time":
				// _, err := time.Parse(time.RFC3339, s)<commit_msg>Validator: instead of lowercasing just use the first char<commit_after>package validators

import (
	"fmt"
	"sort"
	"strings"

	"bitbucket.org/cihangirsavas/gene/schema"
	"bitbucket.org/cihangirsavas/gene/stringext"
)

func GenerateValidator(p *schema.Schema) string {
	validators := make([]string, 0)
	// schemaName := p.Title
	schemaFirstChar := stringext.Pointerize(p.Title)

	for key, property := range p.Properties {
		switch property.Type {
		case "string":
			if property.MinLength != 0 {
				validator := fmt.Sprintf("validator.MinLength(%s.%s, %d)", schemaFirstChar, key, property.MinLength)
				validators = append(validators, validator)
			}

			if property.MaxLength != 0 {
				validator := fmt.Sprintf("validator.MaxLength(%s.%s, %d)", schemaFirstChar, key, property.MaxLength)
				validators = append(validators, validator)
			}

			if property.Pattern != "" {
				validator := fmt.Sprintf("validator.Pattern(%s.%s, \"%s\")", schemaFirstChar, key, property.Pattern)
				validators = append(validators, validator)
			}

			if len(property.Enum) > 0 {
				validator := fmt.Sprintf("validator.OneOf(%s.%s, []string{\"%s\"})", schemaFirstChar, key, strings.Join(property.Enum, "\",\""))
				validators = append(validators, validator)
			}

			switch property.Format {
			case "date-time":
				// _, err := time.Parse(time.RFC3339, s)
{'fraction_non_alphanumeric': 0.1592284417549168, 'fraction_numerical': 0.006051437216338881, 'mean_word_length': 4.135922330097087, 'pattern_counts': {'":': 4, '<': 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': '2867904', 'n_tokens_mistral': 989, 'n_tokens_neox': 867, 'n_words': 171}