Skip to content

feat: Add possibility to register custom formats and their validators. #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlexMinaev19
Copy link

Resolves #152

Added new configuration option Formats that allows you to register custom formats and their validators.

Usage:

v, err := NewValidator(
    document,
    config.WithFormatAssertions(), // required to enable format assertions
    config.WithCustomFormat("capital", func(v any) error {
        s, ok := v.(string)
	if !ok {
		return fmt.Errorf("expected string")
	}

	if s == "" {
		return nil
	}

	r := []rune(s)[0]

	if !unicode.IsUpper(r) {
		return fmt.Errorf("expected first latter to be uppercase")
	}

	return nil
    }),
)

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.89%. Comparing base (8660f37) to head (8dd6f32).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #166      +/-   ##
==========================================
+ Coverage   96.88%   96.89%   +0.01%     
==========================================
  Files          34       34              
  Lines        3791     3804      +13     
==========================================
+ Hits         3673     3686      +13     
  Misses        118      118              
Flag Coverage Δ
unittests 96.89% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add possibility to register custom formats
1 participant