Skip to content

fix: check enums only in responses, never an enum's zero value, and in the replay test - #81

Merged
MarkRosemaker merged 1 commit into
mainfrom
fix/unknown-enum-responses
Nov 15, 2026
Merged

MarkRosemaker merged 1 commit into
mainfrom
fix/unknown-enum-responses

Conversation

@MarkRosemaker

Copy link
Copy Markdown
Owner

Follow-up to #80, found while looking into go-api-libs/notion#21, where notion's coverage fell after the bump.

  • Only types a response can hold get unknownEnum. The client calls it only on what it decoded from a response, so the method on a type that only requests hold was dead code. In notion that was 324 of the 539 generated methods.
  • An enum at its zero value is never treated as unknown, even when the field is required: the object holding it may itself be left out or null. Without this, every recorded page with "cover": null (so Cover.Type == "") and every numbered list item without list_format would have been recorded.
  • In debug mode, the replay test now fails for a recorded success response that holds a value its enum doesn't list:
    if out != nil && out.unknownEnum() {
    	t.Errorf("GetItem: holds a value of an enum the specification does not list")
    }
    So a spec that lags behind what the API sends is caught in tests, not just recorded at runtime. It also exercises the methods on real data. The debug test package gains two recorded calls for this. I checked that changing one recorded status to an unlisted value makes the test fail.

Tested against notion (via a local replace): its replay test passes. A reflection walk over every recorded block and page confirms that no non-empty enum value falls outside the spec. Coverage goes from 74.3% to 77.8% as devtool measures it (Go 1.27.4).

TestMarkUnknownEnums checks that a request-only type gets no method, while response and error types do.


Generated by Claude Code

…n the replay test

unknownEnum was generated for every type holding an enum, though the client
calls it only on a response: types only requests hold now get none, which in
notion is 324 of 539. An enum at its zero value is one left out, even where
required, since what holds it may be left out or null: checking it flagged
every page without a cover. In debug mode, the replay test now fails for a
recorded response that holds a value its enum does not list, so a
specification behind what the API sends is caught, not only recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
@MarkRosemaker
MarkRosemaker merged commit 4b51095 into main Nov 15, 2026
1 check passed
@MarkRosemaker
MarkRosemaker deleted the fix/unknown-enum-responses branch November 15, 2026 16:54
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