Write open enums as anyOf so third-party generators accept openapi.json
Stacked on #1140; retarget to main once it merges.
Why
openapi.json should work with mainstream third-party generators, not only with ours. Measured on #1140's head, two things in the document broke them:
contentEncoding: "byte". It is not an RFC 2045 value, and swift-openapi-generator's parser refuses the whole document:Cannot initialize ContentEncoding from invalid String value byte.- Open enums written as a bare
enumlist. JSON Schema reads a bareenumas closed. swift-openapi-generator's client threw on a status the spec does not list (Cannot initialize FilingStatus from invalid String value rebalancing). openapi-generator's Go output did not compile at all, becauseFilingStatusandProjectConstructionStatusconstants collided (FAILED redeclared).
What changes on the wire
WireFormatSchemaMapperwrites every enum asanyOf [{type: string, enum: [known]}, {type: string}]plusx-basecamp-open-enum: true, with notypeorenumbeside them. There are 10 such schemas.smithy-build.jsonsetsdefaultBlobFormat: binary, so 6 payloads move fromcontentEncoding: bytetobinary.- SPEC §10 "Open Enums" now describes this wire form and what third-party tools make of it. I made that change here rather than in #1140.
Other shapes I measured: a $ref'd Known enum inside the anyOf, the two branches swapped, and x-extensible-enum. All were worse. The $ref form still collides in openapi-generator Go. The other two compile but carry less: either the known values are lost to Swift, or the enum is still closed.
Third-party generators
openapi-consumers/run (or make openapi-consumers) generates code from openapi.json with each tool and compiles it. Each tool runs at a pinned version; the jars are checked against openapi-consumers/checksums.sha256. CI runs this as two new jobs, openapi-consumers-jvm (ubuntu) and openapi-consumers-swift (macos-15). Both jobs feed the Conformance Tests fan-in, so a failure gates. The Swift job selects Xcode 26, since swift-openapi-generator 1.14 needs Swift 6.2. Results, run locally:
| Tool | Version | Generates | Checked by | #1140 head | This PR |
|---|---|---|---|---|---|
| swift-openapi-generator | 1.14.4 (runtime 1.13.4) | types; types + client | swift build, swift test | refuses the document (byte) | compiles; 3/3 decode tests pass |
| fabrikt | 29.3.0 | HTTP models, Jackson and kotlinx.serialization | compileKotlin | compiles | compiles |
| openapi-generator | 7.28.0 | typescript-fetch | tsc with strict | compiles | compiles |
| openapi-generator | 7.28.0 | go | go build, go vet | fails: redeclared constants | compiles |
Unknown values decode. openapi-consumers/swift/Tests/TypesTests uses three fixtures:
- a Filing with
"status": "rebalancing", which decodes, keeps the string, and re-encodes it unchanged; - a known status, which decodes as its case;
- a Project with an unknown
statusandpurpose.
Swift is the strictest decoder of the four, and the tests assert both its known case (value1) and its raw-string fallback (value2). fabrikt types an open enum as String. openapi-generator wraps the raw string (Go struct { String *string }, TypeScript an empty interface), which compiles and passes values through but gives callers no typed known cases. The "Cannot initialize FilingStatus" failure above comes from a scratch run against the closed form, measured before this change. The committed tests are written against the anyOf shape, so against a closed document they fail to compile rather than to decode.
What consumers need: fabrikt's kotlinx models need kotlinx-datetime, jakarta.validation-api and the kotlin.time.ExperimentalTime opt-in. The harness sets all three, as a consumer would.
Our seven generators: output unchanged
Every generator here reads the document back through one collapse step. The step turns anyOf [{type, enum}, {type}] back into {type, enum, x-basecamp-open-enum}, keeping key order:
| SDK | Collapse step |
|---|---|
| TypeScript | typescript/scripts/open-enum-collapse.ts |
| Ruby | wire_formats.rb |
| Python | gen_common.py |
| Kotlin | OpenEnumCollapse.kt |
| Swift | OpenEnumCollapse.swift |
| Rust | rust/generator/src/open_enum.rs |
| Go (for oapi-codegen) | scripts/collapse-open-enums (jq, via scripts/go-oapi-codegen) |
- One contract for all seven. Each implementation is tested against the shared contract in
openapi-consumers/open-enum-collapse.json. Besides the collapse itself, every implementation refuses the same 8 malformed wrappers, including a marker of1or"true"instead of the booleantrue. - No generated file changed. After
make generate(andmake kt-generate-servicesagain after rebasing onto #1140's current head), the generated SDK sources are byte-identical. The one intended difference istypescript/src/generated/openapi-stripped.json, whosecontentEncodingmoves tobinary(it mirrors the document). Generated timestamps were reverted. - The tool catalog is unchanged too.
go/pkg/basecamp/catalog/catalog.json(basecamp-cli's MCP schemas) reads through the same jq collapse inmake catalog/catalog-check, so it is byte-identical to #1140's head.gen-catalognow refuses the rawanyOfform rather than silently publishing it. - Only the collapse reads
enum.make check-open-enum-readersis a new spec-gates step. It finds every file that reads anenumkey: 26 today, each classified inopenapi-consumers/open-enum-readers.jsonas collapse, downstream of a collapse, wire-form test, collapsed-view test, or unrelated. It fails on an unlisted reader, a stale entry, or an entry point (16) that no longer names its collapse. What it can't see: anenumread spelled some way its pattern doesn't match. The drift checks, which regenerate from theanyOfform, cover the behavior instead. - Fixture validation still holds.
check-fixture-coveragestill rejects a wrong-typed open-enum value. Its validator treatsanyOfas at-least-one, so an integerstatusmatches no branch.
Known warnings, not changed here
swift-openapi-generator warns about two things. Both are pre-existing, and decoding is correct either way.
nullable: trueon 18 members.scripts/enhance-openapi-go-types.shwrites these; it is an OpenAPI 3.0 keyword, which the generator translates.{"type": "null"}inside ananyOf, onDraft.parentandTemplateLibraryCardTables.kanban_boardset. The generator skips it but still decodesnull.
Moving those to 3.1 form changes what oapi-codegen generates for Go, so it is a separate change.
Label
enhancement: the SDKs' APIs and generated code are unchanged. Readers of openapi.json outside this repo that read a top-level enum off these 10 schemas will see a different shape. If you count that as breaking, relabel; before 1.0 both labels mean a minor release.
Checks run locally
make check came back green except for rs-lint (cargo fmt), which I fixed. After the rebase and the catalog change I ran these again, and they pass:
rs-lintkt-check-driftkt-check-optional-arrays-and-scalarscheck-open-enum-readersgo-check-driftcatalog-checkmake lint-actions(actionlint, zizmor)openapi-consumers/run all
Not from this change: Bundler Audit, npm Audit and Trivy (Ruby SDK) are red on dependency advisories, and GitHub Actions audit is red on a shellcheck SC2337 warning in existing steps (test.yml lines that predate this PR, release-kotlin.yml, release-typescript.yml).
Outside review
I ran the dual-model review script on 32aaf98b and fixed what it found in 0d2316d4: the Swift job's toolchain, the fan-in, the harness's --spec handling, verifying a jar before caching it, and fresh inside $(...); Swift's collapse taking a JSON 1 as true; Rust's contract test ignoring key order; the Swift project test not checking the enum branches; the SPEC text on openapi-generator's types; and two enum read spellings plus Swift's Generated/ in the reader check. One I declined: overlapping run invocations in one checkout share output paths. The script now says to run one at a time; CI runs each job in its own checkout.