Skip to content

fix(schema): preserve numeric and boolean enum types - #410

Open
takiAA wants to merge 2 commits into
charmbracelet:mainfrom
takiAA:fix/typed-enum-values
Open

takiAA wants to merge 2 commits into
charmbracelet:mainfrom
takiAA:fix/typed-enum-values

Conversation

@takiAA

@takiAA takiAA commented Oct 4, 2026 •

Copy link
Copy Markdown

An int field tagged enum:"1,2" currently generates {"type":"integer","enum":["1","2"]}. The numeric values fail the enum constraint, while the string values fail the type constraint. Boolean and floating-point fields have the same problem.

Parse enum tags according to the generated field type so numeric and boolean values keep their JSON types. String enums remain strings, including values such as "true" and "1". Integer parsing preserves the full signed/unsigned 64-bit range; number enums use json.Number to avoid introducing float rounding. Unparseable tags keep their previous string representation.

The regression tests validate permitted and out-of-enum values through ParseAndValidate, cover a pointer to a named integer type, and check exact serialization of large integer enums. The validation and integer-serialization regressions fail on the unchanged code and pass with the fix.

Validation on Go 1.27.0, macOS arm64:

  • go test ./... -count=1 -timeout=30m passed.
  • go build ./..., gofumpt, and git diff --check passed.
  • Both example modules build with a temporary -modfile and -mod=mod. Their checked-in module files report go: updates to go.mod needed on both the unchanged baseline and this branch; this PR changes no dependency files.
  • golangci-lint v2.14.0 passed with 0 issues after merging the upstream fix from fix: stop matching GOAWAY by a deprecated type聽#415. The full test suite was rerun and passed on the updated branch.

Synced with main after #415 fixed the pre-existing http2.GoAwayError deprecation. GitHub Actions lint now passes.

  • I have read CONTRIBUTING.md.
  • New-feature discussion: not applicable (bug fix).

@takiAA
takiAA requested a review from andreynering as a code owner October 4, 2026 15:23
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.

1 participant