Skip to content

[5/11] Add oneof checker - #228

Merged
cinar merged 1 commit into
mainfrom
p1-05-oneof
Sep 5, 2026
Merged

[5/11] Add oneof checker#228
cinar merged 1 commit into
mainfrom
p1-05-oneof

Conversation

@cinar

@cinar cinar commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Problem

Without oneof, every enum-shaped field needs a hand-written RegisterMaker call — the single most commonly cited DX gap across every one of the six source reports behind this issue list.

Fix

Add oneof, following the established checker file pattern:

  • IsOneOf is generic (IsOneOf[T comparable]) so it's usable standalone for any comparable type, not just strings.
  • Syntax correction from the filed issue: the tag is oneof:admin,user,guest (comma-separated), not oneof:admin user guest (space-separated) as originally proposed. Checker tag fields are already split on whitespace before an individual checker's own params are parsed (maker.go's makeChecks does strings.Fields(config) over the whole tag first), so a space-separated value list literally can't be parsed by the existing tag DSL — it would be seen as multiple unrelated checker names. Followed the precedent already set by credit-card:visa,mastercard instead.
  • The error message includes the allowed values via a generic newOneOfError helper (same pattern as the existing newGteError/newEqFieldError), so a failure is actionable instead of a bare code: "Value must be one of admin, user, guest.".
  • schema_maker.go maps oneof to JSON Schema's Enum — a field that existed on Schema but nothing previously populated.
  • NOT_ONE_OF message with an {{ .allowed }} placeholder added to all 23 locale files plus en-US.
  • Documented in the README's checker table, with the comma-vs-space syntax called out.

Testing

  • oneof_test.go: valid/invalid, generic non-string usage (int), error message content, empty-config panic, non-string-field panic, struct-tag valid/invalid.
  • TestJSONSchemaOneOfEnum for the Enum mapping.
  • Full suite passes, 100% coverage maintained.
  • go vet, gosec, revive clean.

Fixes #202


Chain note: PR 5 of 11 — branched locally on top of the now-merged uuid PR, then rebased onto current main so the diff here is only this PR's own changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i

Without oneof, every enum-shaped field needs a hand-written
RegisterMaker call -- the single most commonly cited DX gap across the
source reports.

- IsOneOf is generic (IsOneOf[T comparable]) so it works standalone
  for any comparable type, not just strings.
- The reflect-based maker splits its config on comma, not space:
  checker tag fields are already split on whitespace before an
  individual checker's own params are parsed, so "oneof:foo bar baz"
  as originally proposed can't actually be parsed by the existing tag
  DSL. Followed the precedent already set by
  credit-card:visa,mastercard instead: oneof:admin,user,guest.
- The error message includes the allowed values via a generic
  newOneOfError helper (same pattern as newGteError/newEqFieldError),
  so failures are actionable instead of a bare code.
- schema_maker.go maps oneof to JSON Schema's Enum, which nothing
  previously populated.
- NOT_ONE_OF message with an {{ .allowed }} placeholder added to all
  23 locale files plus en-US.
- Documented in the README's checker table, with the comma-vs-space
  syntax called out explicitly.

Fixes #202

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a87659f) to head (a4bf334).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #228   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           53        54    +1     
  Lines          958       983   +25     
=========================================
+ Hits           958       983   +25     

☔ View full report in Codecov by Harness.
📢 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.

@cinar
cinar merged commit 3511512 into main Sep 5, 2026
8 checks passed
@cinar
cinar deleted the p1-05-oneof branch September 5, 2026 17:11
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 oneof checker (enum-style validation)

1 participant