Skip to content

Overlay mechanism for openapi/asyncapi specs: OpenAPI Overlay Specification + shared JSONPath in common-json #2127

Closed

Description

@jfallows

Follow-up to #2113 item 3. That issue's mqttKafka.channels → x-zilla-mqtt-kafka extension work surfaced the need for an overlay escape hatch for specs an operator can't edit directly (fetched from a schema registry, etc.), but left the overlay mechanism itself unscoped — no existing pattern in the codebase to anchor a design decision, and applying the wrong shape risks rework. Capturing the design discussion here before it evaporates.

Proposal

Use the real OpenAPI Overlay Specification (1.0.0) rather than inventing a bespoke format. It's a JSONPath-targeted list of actions: [{target, update} | {target, remove}] applied against the original document — not raw JSON Patch, but conceptually similar (target-based mutation without editing the source). Despite the "OpenAPI" branding, the mechanism itself is document-shape-agnostic — nothing about it is tied to the OpenAPI schema, so it applies equally well to AsyncAPI documents.

Where it should live

JSONPath/actions-application engine → common-json. That module already owns JSON Schema validation, streaming transforms (JsonTransform/JsonTransforms), and ref resolution (JsonRefResolver) — a natural, protocol-agnostic home for a JSONPath evaluator + Overlay-actions applier. This keeps the mechanism generic rather than openapi-specific.

Materialize step → common-openapi / common-asyncapi, at the existing catalog-resolve seam. Every one of the four consumers — binding-openapi, binding-asyncapi, binding-openapi-asyncapi, binding-mcp-openapi — independently repeats the identical sequence in their *CompositeGenerator.generate():

final String payload = handler.resolve(schemaId);
...
final OpenapiView openapi = OpenapiView.of(tagIndex++, label, parser.parse(payload), configs);

Insert the overlay-materialize step once, right there (apply overlay actions to payload before parser.parse(payload)), in the shared common-openapi/common-asyncapi code each of the four already depends on. Every consumer gets a fully materialized doc for free — no per-binding overlay-awareness needed.

Deliberately not the CatalogHandler SPI itself: that's a generic, protocol-agnostic abstraction shared with unrelated consumers (e.g. Kafka message validation via catalog-inline/catalog-schema-registry/etc.) — baking an openapi/asyncapi-specific concept into it would leak abstraction the other direction.

Config surface

options.specs.<name>.overlay on the consuming binding, pointing at the overlay document (still needs design: inline overlay content vs. a reference to a separately-cataloged overlay doc — probably worth mirroring the existing catalog: reference shape for consistency).

Known blocker to scope up front

No JSONPath dependency exists anywhere in the tree today. runtime/'s module system rules (see runtime/AGENTS.md) forbid non-modular/automatic-module dependencies anywhere in the runtime graph — any candidate JSONPath library needs a real module-info.class, or the (fairly small) JSONPath subset the Overlay spec actually needs gets implement directly in common-json instead of pulling in a dependency. This should be resolved as part of scoping the work, before implementation starts.

Out of scope / already handled separately

The x-zilla-mqtt-kafka channel extension (the other half of #2113 item 3, replacing options.mqttKafka.channels) does not depend on this and is landing independently in #2113.

Activity

  1. jfallows commented on Jul 11, 2026

    @jfallows
    ContributorAuthor

    Pushed an initial implementation on claude/github-issue-2127-s1tocw (also branched in zilla-docs).

    Blocker 1 (JSONPath dependency) resolved: no JSONPath library is added. common-json gets a small hand-rolled JsonPath (root, dot/bracket member access, integer indices incl. negative, and .*/[*] wildcards — the subset real Overlay documents actually use) plus JsonOverlay/JsonOverlayAction, which parse and apply an OpenAPI Overlay Specification 1.0.0 document to a JsonValue tree. Update merges into matched objects (recursively), appends to matched arrays, or replaces matched scalars; remove deletes matched nodes, highest array index first so a single wildcard match removes safely. Actions are applied in order against the document as edited by prior actions. 33 new unit tests.

    Blocker 2 (config surface) — concrete proposal, implemented for one binding: options.specs.<label>.overlay, shaped identically to the existing specs.<label>.catalog reference ({ <catalogName>: { subject, version } }), resolved via the same CatalogHandler. Wired into binding-openapi's OpenapiCompositeGenerator at exactly the seam described in this issue — between handler.resolve(schemaId) and parser.parse(payload) — plus the config adapter, JSON schema patch, and common-openapi's shared OpenapiSpecificationConfig. A new test (OpenapiServerGeneratorTest.shouldApplyOverlayBeforeGeneratingRoutes) proves an overlay-added path makes it into the generated composite. Docs updated in zilla-docs.

    Scoped out of this change, left as follow-up: wiring the same overlay field into binding-asyncapi, binding-openapi-asyncapi, and binding-mcp-openapi. The mechanism and config shape are now established and this is mechanical repetition of the same pattern per binding (each has its own config classes and JSON schema patch), but I didn't want to multiply an unreviewed config-surface decision across four public schemas in one shot. Happy to extend to the rest once the shape above looks right, or if you'd rather change it before it spreads further.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions