Skip to content

build(api): publish a bundled api.json for codegen-friendly named types#368

Merged
jlimatampersand merged 1 commit into
mainfrom
eng/openapi-bundled-artifact
Jul 3, 2026
Merged

build(api): publish a bundled api.json for codegen-friendly named types#368
jlimatampersand merged 1 commit into
mainfrom
eng/openapi-bundled-artifact

Conversation

@jlimatampersand

Copy link
Copy Markdown
Contributor

What

Publish a bundled variant of the API spec at api/generated/api.bundled.json, alongside the existing dereferenced api/generated/api.json.

The bundled artifact is produced with Redocly (dereference: false): external-file $refs are merged into a single document's components, while internal $refs are preserved — e.g. Installation.connection stays a $ref to the Connection component rather than being inlined.

Why

The dereferenced api.json inlines every $ref. Code generators that consume it (e.g. oapi-codegen, used by amp-common) therefore emit anonymous nested structs instead of reusing named component types. That means Installation.Connection in generated Go is an inline struct { ... }, not the shared Connection type — so it can't be passed to functions expecting a Connection, and every nested object is duplicated.

Generating from the bundled artifact instead yields shared, named types (Connection, Group, Config, …). This PR just publishes the artifact; the dereferenced JSON is unchanged, so docs generation is unaffected.

Why Redocly (not swagger-parser's bundle)

@apidevtools/swagger-parser's bundle() de-duplicates repeated schemas by pointing later $refs into the first occurrence's properties (e.g. #/components/schemas/Config/properties/content) and can leave dangling refs for recursive schemas. oapi-codegen's loader can't consume that (map key "properties" not found). Redocly hoists every shared schema into components/schemas with clean #/components/schemas/... refs, which generators handle correctly.

Changes

  • scripts/generate-json.ts: after the existing dereference pass, add a bundle pass (Redocly bundle, dereference: false) writing api/generated/api.bundled.json.
  • package.json / pnpm-lock.yaml: add @redocly/openapi-core devDependency.
  • api/generated/api.bundled.json: the generated artifact (169 named schemas; all $refs resolve to #/components/schemas/..., none into properties).

Verified

  • pnpm run gen:json regenerates both the deref'd and bundled outputs; the deref'd api.json is byte-identical to main.
  • Generating amp-common's Go types from the bundled file with oapi-codegen succeeds and produces named types (Installation.Connection Connection, Config Config, Group *Group); the result compiles.

Follow-ups (separate PRs)

  • amp-common: point its Makefile at api.bundled.json and commit the regenerated api.gen.go.
  • server: consume the named Connection type in the subscribe request builders.

🤖 Generated with Claude Code

Add a bundled variant of the API spec at api/generated/api.bundled.json,
generated with Redocly (dereference: false) so external-file $refs are
merged into components while internal $refs are preserved (e.g.
Installation.connection stays a $ref to the Connection component).

The existing dereferenced api.json inlines every $ref, which makes code
generators (oapi-codegen, consumed by amp-common) emit anonymous nested
structs instead of reusing named component types. Consumers that want
shared, named Go types (Connection, Group, Config, ...) can generate from
the bundled artifact instead. The dereferenced JSON is unchanged, so docs
generation is unaffected.

Redocly is used rather than swagger-parser's bundle because it hoists
every shared schema into components/schemas with clean
'#/components/schemas/...' refs; swagger-parser points duplicate refs into
the first occurrence's properties, which oapi-codegen cannot consume.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jlimatampersand jlimatampersand merged commit 49f7b03 into main Jul 3, 2026
2 checks passed
@jlimatampersand jlimatampersand deleted the eng/openapi-bundled-artifact branch July 3, 2026 00:30
jlimatampersand added a commit to amp-labs/amp-common that referenced this pull request Jul 6, 2026
…types)

Point the openapi codegen at the openapi repo's new bundled artifact
(api/generated/api.bundled.json) instead of the fully dereferenced
api.json. The bundled spec preserves internal $refs, so oapi-codegen now
emits shared, named component types for nested properties instead of
anonymous inline structs.

Most visibly, Installation.Connection is now the named Connection type
(and Config/Group/etc. are named), so callers can pass them to functions
expecting those types and there is no per-site struct duplication.
api.gen.go shrinks from ~12.2k to ~4.5k lines.

Depends on amp-labs/openapi#368 (publishes api.bundled.json). commit.json
points at that PR's head commit; the auto-gen workflow will refresh it
once the openapi change lands on main.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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