Skip to content

feat(apitest): RoundTrip checks nothing is dropped, Null checks a union's null - #8

Merged
MarkRosemaker merged 1 commit into
masterfrom
feat/round-trip-strict
Nov 15, 2026
Merged

MarkRosemaker merged 1 commit into
masterfrom
feat/round-trip-strict

Conversation

@MarkRosemaker

Copy link
Copy Markdown
Contributor

Two checks for the round-trip tests openapi-codegen generates, part of fixing go-api-libs/notion#21:

  • RoundTrip: when the value encodes as an object, it now also decodes that object with an extra member no type declares. A strict decoder must refuse it, or keep it as additional properties do. Silently dropping it fails the test. This is what debug mode relies on to notice what the spec doesn't know. It also runs each union alternative's error path in the generated decoders, which no test reached before.
  • Null[T]: checks that a union holding no alternative encodes as null, and that null decodes as a union holding none, as when an API sends "cover": null.

Both are tested here: refused, kept, and dropped for RoundTrip; and for Null, a union, a type that isn't null, a type that decodes null as a value, and errors when encoding or decoding fail.

I checked these against openapi-codegen's golden tests, notion and pixellab, using local replace directives: no generated type drops a member or mishandles null. With the matching codegen change (separate PR), notion goes from 77.8% to 83.6% as devtool measures it.


Generated by Claude Code

…on's null

RoundTrip now also decodes what it encoded with a member no type declares:
a strict decoder must refuse it, or keep it as additional properties, never
drop it silently. Null checks that the zero of a union, holding no
alternative, encodes as null and that null decodes as it, as an API sends a
member it leaves unset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y
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