build(api): publish a bundled api.json for codegen-friendly named types#368
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Publish a bundled variant of the API spec at
api/generated/api.bundled.json, alongside the existing dereferencedapi/generated/api.json.The bundled artifact is produced with Redocly (
dereference: false): external-file$refs are merged into a single document'scomponents, while internal$refs are preserved — e.g.Installation.connectionstays a$refto theConnectioncomponent rather than being inlined.Why
The dereferenced
api.jsoninlines every$ref. Code generators that consume it (e.g.oapi-codegen, used byamp-common) therefore emit anonymous nested structs instead of reusing named component types. That meansInstallation.Connectionin generated Go is an inlinestruct { ... }, not the sharedConnectiontype — so it can't be passed to functions expecting aConnection, 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'sbundle()de-duplicates repeated schemas by pointing later$refs into the first occurrence'sproperties(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 intocomponents/schemaswith clean#/components/schemas/...refs, which generators handle correctly.Changes
scripts/generate-json.ts: after the existing dereference pass, add a bundle pass (Redoclybundle,dereference: false) writingapi/generated/api.bundled.json.package.json/pnpm-lock.yaml: add@redocly/openapi-coredevDependency.api/generated/api.bundled.json: the generated artifact (169 named schemas; all$refs resolve to#/components/schemas/..., none intoproperties).Verified
pnpm run gen:jsonregenerates both the deref'd and bundled outputs; the deref'dapi.jsonis byte-identical tomain.oapi-codegensucceeds and produces named types (Installation.Connection Connection,Config Config,Group *Group); the result compiles.Follow-ups (separate PRs)
amp-common: point its Makefile atapi.bundled.jsonand commit the regeneratedapi.gen.go.server: consume the namedConnectiontype in the subscribe request builders.🤖 Generated with Claude Code