Skip to content

test(generator): a spec that crosses features, generated, compiled, and vetted - #119

Merged
giraffesyo merged 4 commits into
canaryfrom
combinations-corpus
Aug 21, 2026
Merged

test(generator): a spec that crosses features, generated, compiled, and vetted#119
giraffesyo merged 4 commits into
canaryfrom
combinations-corpus

Conversation

@giraffesyo

Copy link
Copy Markdown
Member

Depends on #117; this branch is stacked on it, since the corpus spec composes a multipart body through allOf. Merge that one first.

Why

The suite has 62 e2e tests, and each drives one feature through a spec written for it. None of them catch a feature that quietly stops happening in the presence of another, or one that disappears entirely while the package still builds.

Every bug from the last stretch was found by generating real specs by hand, and every one was invisible here:

bug what a per-feature test could not see
#92 iterators generated for no operation at all
#114 a page parameter that is not a number
#90 a file part sent as base64 text
#112 a paginated endpoint whose response is the page

What this adds

testdata/combinations.yaml, a 3.1 spec that crosses features rather than listing them:

  • three pagination styles in one package, one iterating a union
  • a multipart body that composes a schema through allOf
  • webhooks beside callbacks, with names that normalize together
  • response headers and struct properties that normalize together
  • schemas named Client and DefaultBaseURL, which the templates declare
  • an operation that opts out of the document's security
  • a discriminated union whose variants pin their tag with const and share a base
  • a content-serialized parameter, an allowReserved one, and a union-typed one

The test asserts each of those survived, then compiles and vets the output. go vet rather than build alone: it catches what compiles and is still wrong.

Assertions compare with whitespace collapsed, since the files reach the test before goimports aligns them.

It found one immediately

An inline multipart body composed through allOf lost its file parts, typing them as byte slices so the encoder sent base64 text in ordinary fields. That is the same failure #90 fixed for a body written as an object, in the path #117 introduced. Fixed in #117, with the commit that adds it.

gofmt, golangci-lint, go vet ./..., and go test ./... pass.

…ed schemas

allOf is JSON Schema 2020-12 composition, which 3.1 uses, and it is valid
anywhere a schema is. convertSchema composes it for a named component schema
and resolveGoType, which types every inline property, never looked at it, so
a property that composed anything resolved to any.

In a 3.1 spec today:

	allOf: [$ref, {inline object}]   ->  any
	allOf: [$ref]                    ->  any
	$ref with sibling keywords       ->  the referenced type
	anyOf: [$ref, {type: null}]      ->  the referenced type

The first two are the inconsistency: the same composition on a named schema
builds a struct. A lone $ref inside an allOf says the value must match that
schema, so it resolves to it; anything more composes a shape of its own and
is named like other inline schemas, keeping both what it embeds and what it
adds.

The two idioms 3.1 offers instead already worked, and now have a test that
keeps them working.
…parts

The composition path this PR adds converted its schema as if it were sent as
JSON, so a multipart body written as allOf typed its binary properties as
byte slices and the encoder sent them as base64 text in ordinary fields, the
same failure #90 fixed for a body written as an object.

Multipart is a property of where a schema is used, so the composition path
consults it the same way the object path does.
…nd vetted

The tests around this one each drive a single feature through a spec written
for it. What none of them catch is a feature that quietly stops happening in
the presence of another, or one that disappears while the package still
builds. Every bug found by generating real specs by hand was invisible to
this suite: iterators generated for no operation, a page parameter that is
not a number, a file part that turned back into base64 text.

testdata/combinations.yaml crosses them deliberately: three pagination
styles in one package, one of them iterating a union, a multipart body that
composes a schema, webhooks beside callbacks, headers and properties whose
names normalize together, schemas named after identifiers the templates
declare, and an operation that opts out of the document's security.

The assertions are features that have each regressed at least once, and the
generated package is compiled and vetted rather than only compiled: vet
catches what builds and is still wrong.

Writing it found one more, fixed in the commit before this: a multipart body
composed through allOf lost its file parts.
@giraffesyo
giraffesyo merged commit 48e7bec into canary Aug 21, 2026
7 checks passed
@giraffesyo
giraffesyo deleted the combinations-corpus branch August 21, 2026 19:39
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