Skip to content

[4/11] Add uuid checker - #227

Merged
cinar merged 3 commits into
mainfrom
p1-04-uuid
Sep 5, 2026
Merged

[4/11] Add uuid checker#227
cinar merged 3 commits into
mainfrom
p1-04-uuid

Conversation

@cinar

@cinar cinar commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Problem

UUIDs are one of the most common identifier formats in modern APIs, and validating one currently requires a custom RegisterMaker call — a common enough gap that every source report flagged it as a top adoption blocker.

Fix

Add uuid as a built-in checker, following the established per-checker file pattern (see email.go):

  • IsUUID/checkUUID/makeUUID, reusing IsRegexp (cached since Performance: regexp checker recompiles the pattern on every call #198) rather than hand-rolling a match.
  • Accepts any UUID version/variant: 32 hex digits grouped 8-4-4-4-12, case-insensitive, per RFC 4122 — not narrowed to v4 only, since the tag is just uuid with no version parameter.
  • Registered in maker.go's makers map.
  • schema_maker.go maps it to JSON Schema's "format": "uuid".
  • NOT_UUID message added to all 23 locale files plus en-US, verified against locales_test.go's placeholder-parity check.
  • Documented in the README's checker table.

Testing

  • uuid_test.go: valid/invalid, uppercase, wrong-grouping, non-string-field panic (existing contract), struct-tag valid/invalid.
  • TestJSONSchemaUUIDFormat for the schema mapping.
  • Full suite passes, 100% coverage maintained.
  • go vet, gosec, revive clean. gofmt -l clean on every touched file.

Fixes #201


Chain note: PR 4 of 11 — stacked on p1-03-omitempty (#226).

🤖 Generated with Claude Code

https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i

cinar and others added 3 commits September 5, 2026 16:56
ErrorWithLocale parsed the localized message string into a
*template.Template on every single call, even though the large
majority of messages ("Required value is missing.", "Not a valid
email address.", ...) contain no {{ }} placeholders at all and don't
need template parsing or execution in the first place.

Add a fast path: if the message contains no "{{", return it directly.
For the messages that do have placeholders, parse once and cache the
*template.Template keyed by the message string (errorTemplateCache,
same pattern as regexpCache from #198) instead of re-parsing on every
call.

Fixes #199

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
Optional fields that must still be valid when present required a
workaround: either building the struct conditionally, or leaning on
required-if-style tricks. Every major struct-tag validator has a
shorthand for this; Checker didn't.

Add omitempty as a tag pipeline modifier, not a registered checker:
reflectCheckFieldWithConfig strips it out of the config string
(extractOmitEmpty) and, if the field's own value IsZero(), skips
running the rest of that field's checks entirely. It looks at the
field's original value, not one already transformed by an earlier
normalizer in the same tag, so "trim omitempty required" on
whitespace-only input still fails required after trimming.

With the "@" prefix it applies to a slice/map container instead of its
items, following the same convention "@" already uses everywhere else
in the tag DSL. JSONSchema now treats it like a normalizer (skipped
rather than recorded in XChecker), since it's a pipeline instruction,
not a shape constraint. Documented in the README, including the
documented omitempty+required contradiction (omitempty wins: required
never runs on a zero value).

Fixes #200

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
UUIDs are one of the most common identifier formats in modern APIs,
and validating one currently requires a custom RegisterMaker call.
Add it as a built-in checker.

- IsUUID/checkUUID/makeUUID follow the established checker pattern,
  reusing IsRegexp (cached since #198) rather than hand-rolling a
  match.
- Accepts any UUID version/variant: 32 hex digits grouped 8-4-4-4-12,
  case-insensitive, per RFC 4122.
- Registered in maker.go's makers map under "uuid".
- schema_maker.go maps it to JSON Schema's "format": "uuid".
- NOT_UUID message added to all 23 locale files plus en-US.
- Documented in the README's checker table.

Fixes #201

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
Base automatically changed from p1-03-omitempty to main September 5, 2026 17:06
@cinar
cinar merged commit a87659f into main Sep 5, 2026
@cinar
cinar deleted the p1-04-uuid branch September 5, 2026 17:06
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.

Add uuid checker

1 participant