Skip to content

feat: debug mode records a response holding an unknown enum value - #80

Merged
MarkRosemaker merged 1 commit into
mainfrom
feat/record-unknown-enums
Nov 15, 2026
Merged

MarkRosemaker merged 1 commit into
mainfrom
feat/record-unknown-enums

Conversation

@MarkRosemaker

Copy link
Copy Markdown
Owner

A value of an enum that the specification does not list still decodes, since an enum is a plain string or number, so debug mode never recorded it. Now it does.

How: rather than writing out a v.Foo != nil && v.Foo.Bar != nil && !v.Foo.Bar.MyEnum.Valid() chain at each call site, debug mode gives each type that holds an enum an unknownEnum method, which reaches every enum the type holds:

func (v *Item) unknownEnum() bool {
	return v.Status != "" && !v.Status.Valid() ||
		slices.ContainsFunc(v.Events, func(x Event) bool { return x.unknownEnum() }) ||
		func() bool { for _, x := range v.Labels { if !x.Valid() { return true } }; return false }()
}
  • Members, pointers, lists, maps (keys and values), union alternatives, embedded allOf parts, tuples and named list/map types are followed. Type aliases resolve to what they alias. A type that refers to itself is handled.
  • An optional member at its zero value was left out, so it is not an unknown value. A required one, a list element or a map value is checked strictly.
  • The client calls the check on what it decoded (success or error body) only when ia != nil, i.e. when the client is in debug mode at runtime, and records the call once with c.keep. Clients not generated with -debug don't change at all: no method and no check. The non-debug golden files are untouched.

Tests

  • The debug spec gains enums in each position: an optional member, a list of objects, a map, a union alternative, and a list response.
  • The new TestDebug_UnknownEnum checks that each unknown value is recorded with its response, and that known values or a missing optional one are not.
  • An untagged union already rejects an alternative whose enum value it doesn't know, so in debug mode that case was already recorded through lenient decoding; the test reflects that.
  • TestEnumsCheck covers nested shapes the specs don't reach: map keys, a pointer to a slice, nested lists, type aliases, and a self-referencing type with no enum.
  • As a one-off check (not committed), the full golden spec was generated in debug mode: all 30 unknownEnum methods compile.

The debug mode section of the README now mentions this.


Generated by Claude Code

A value of an enum the specification does not list decodes, so debug mode
never recorded it. In debug mode, each type that holds an enum, through its
members, lists, maps, pointers and union alternatives, gets an unknownEnum
method, and the client records the call when what it decoded holds a value its
enum's Valid rejects. An optional member left out, at its zero value, is no
unknown value. Outside debug mode, nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
@MarkRosemaker
MarkRosemaker merged commit 5173249 into main Nov 15, 2026
1 check passed
@MarkRosemaker
MarkRosemaker deleted the feat/record-unknown-enums branch November 15, 2026 15:18
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.

2 participants