Skip to content

feat(binding-openapi,binding-asyncapi): servers subset-selection - #2079

Merged
jfallows merged 21 commits into
developfrom
claude/zilla-config-consistency-65bxs2
Jul 11, 2026
Merged

jfallows merged 21 commits into
developfrom
claude/zilla-config-consistency-65bxs2

Conversation

@jfallows

@jfallows jfallows commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

Completes the servers/server split proposed in #2069. A prior change added a singular server deployment-target override for kind: client on both openapi and asyncapi. This PR adds the complementary subset-selection for the plural servers, so a config can compile only a subset of the document-declared servers into the generated composite instead of all of them:

  • openapi: options.specs.<label>.paths: [/v1, ...] — selects document-declared servers by URL path.
  • asyncapi: options.specs.<label>.names: [production, ...] — selects by the AsyncAPI 3.x named server key.

Selector shapes differ per binding because the underlying documents differ: OpenAPI servers are positional/anonymous (no name field), so selection is by path; AsyncAPI 3.x servers are a named map, so selection is by name. Omitting the selector preserves today's behavior of activating every declared server.

Wired into every place each binding's composite generators enumerate servers: client dial-target resolution, kind: server port binding (tcp/tls), per-operation HTTP request/route generation for openapi, and protocol/kafka-bootstrap/SSE gating for asyncapi.

Includes adapter round-trip unit tests, schema validation fixtures, and a K3PO integration test (OpenapiServerIT.shouldCreatePetWithPathsSelection) proving the filter narrows the generated composite end-to-end, not just that config parses.

Fixes #2069


Generated by Claude Code

claude added 11 commits July 9, 2026 15:58
…for kind: client/server

Add options.specs.<label>.paths (openapi, selects by document server path)
and options.specs.<label>.names (asyncapi, selects by named server key) so
a subset of document-declared servers can be compiled into the generated
composite instead of all of them. Complements the prior singular `server`
deployment-target override for kind: client. Omitted selector preserves
today's behavior of activating every declared server.
… drop with

The with/when split only makes sense for protocol-mapping bindings
(mcp-openapi, openapi-asyncapi) where when and with express two different
vocabularies. binding-openapi is single-vocabulary, so tag and glob-operation
were match/trigger criteria masquerading as with fields; they now live on
when alongside spec/operation, and the tag+operation exclusivity restriction
is lifted since both can now combine as ordinary AND'd match criteria.

with itself is removed: its only other job (relabeling a match to a
different spec/operation) was untested and redundant with exit:/guarded:,
which already give routes per-operation dispatch independent of with.
Server and proxy kinds now select operations via when (spec, operation
exact-or-glob, tag), matching binding-openapi. with.operation on proxy
is now optional and falls back to the matched when-side operation name
when omitted, unifying the previously separate exact/bulk match paths
in AsyncapiProxyGenerator. AsyncapiConditionConfig/OpenapiConditionConfig
matches(...) params renamed apiId/operationId -> spec/operation for
consistency. kind: client keeps routes:false (no dispatch mechanism to
back it).
…g-mcp-openapi): servers/server redesign and auto-derived guards

Workstream A: replace options.specs.<label>.paths/.names compile-time
exclusion filters with route-level when.servers[] dispatch, consistent
with the existing spec/operation/tag condition fields. Fix options.server
to compose as a genuine path prefix on top of each doc-declared server
(previously silently dropped for kind: client, unsupported for kind:
server). Renarrow OpenapiCompositeId/AsyncapiCompositeId bit-packing to
carry a per-server index for openapi's real per-request :path dispatch;
asyncapi's when.servers[] stays a per-operation set-membership filter
since its generated routes never vary by server.

Workstream B: replace four separately-broken ad-hoc guard mechanisms
(JWT-bearer-only with NPE risk, first-alternative-only + oauth2-only,
two untested hardcoded "%s:jwt0" guard names with no such guard ever
defined) with a shared fail-open OpenapiGuardResolver/AsyncapiGuardResolver
(common-openapi/common-asyncapi), auto-deriving guarded: from each spec's
declared OpenAPI/AsyncAPI security requirements mapped through a new
options.specs.<label>.security config map. Within one alternative, an
unmapped security requirement is dropped rather than denying the whole
operation; OR-alternatives and AND-of-distinct-guards stay denied since
Zilla routes can reference only one guard. Wires into binding-openapi,
binding-asyncapi (server + both proxy guard sites), binding-openapi-asyncapi
(reviving a previously dead/commented guard call site), and migrates
binding-mcp-openapi's existing fail-closed guard resolution onto the same
shared resolver, flipping it to the same fail-open policy.

Also fixes two related :authority invariant violations found while
touching binding-mcp-openapi's server-resolution code: both
resolveServerFromSpec() and resolveServerOverride() now carry an
explicit scheme-derived port (443/80) rather than a bare host, matching
the port defaulting binding-openapi/binding-asyncapi already apply via
OpenapiServerView.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…s/server redesign

binding-asyncapi.spec's SchemaTest.shouldValidateMqttClientWithNames and
binding-openapi.spec's SchemaTest.shouldValidateClientWithPaths/
shouldValidateServerWithPaths referenced client.mqtt.names.yaml/
client.paths.yaml/server.paths.yaml, deleted or renamed when
options.specs.<label>.paths/.names were replaced with when.servers[]
route conditions. These spec-project tests live in a different location
from the runtime module's adapter tests already updated for that change,
so they were missed and broke CI. Add coverage for the renamed
server.route.servers.yaml/server.route.prefix.yaml fixtures instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…orm request lines

decodeStartLine's absolute-form branch (GET http://host/path HTTP/1.1)
took :authority directly from the request-line target's authority
component with no port defaulting, unlike the Host-header path and the
HTTP/2 header-block decode path, both of which already apply SCHEME_PORTS
(80/443) when the value carries no explicit port. A request with no
explicit port in its absolute-form target produced a bare-host
:authority, violating the explicit-port invariant every HttpBeginEx
producer must uphold for dynamic downstream TCP resolution (e.g.
sys:tcp_client).

Adds a new ArchitectureIT scenario (network + application-side, plus the
spec-level self-consistency counterpart) proving the decoded :authority
now carries the scheme-derived default port; confirmed it fails for the
right reason (test times out, no route matches the bare-host authority)
before the fix.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…ind: client to sys:tcp_client

options.tcp was a redundant escape hatch for both kind: client and
kind: server, with zero test coverage of its backlog/nodelay/keepalive
tuning fields. For kind: client it also silently won over the
resolveServer()/doc-declared-server destination resolution, meaning the
generated tcp_client0 never actually exercised dynamic ProxyBeginEx-based
resolution.

kind: client now exits to the engine-native sys:tcp_client binding
(zero operator authoring, confirmed bare — no options/routes) instead of
generating its own tcp_client0; tls_client0's own exit repoints the same
way. sys:tcp_client only resolves via TcpBindingConfig's fully-dynamic
ProxyBeginEx branch, which requires an explicit-port :authority already
present on the outbound HttpBeginEx — an invariant already upheld by
every producer that constructs one directly (fixed at HttpServerFactory's
absolute-form decode path and mcp-openapi's server-resolution code in
prior commits) and simply relayed unmodified by OpenapiClientFactory/
AsyncapiClientFactory, so no runtime change was needed in either factory.

kind: server keeps generating its own tcp_server0/tls_server0 exactly as
before; only the manual options.tcp override escape hatch is removed,
since bind host/port already falls back to the doc's declared servers.

Migrates the 12 fixtures that declared options.tcp: 7 whose tcp host:port
already matched the doc's own declared server now rely on that fallback;
5 whose test setup intentionally dials a different local port (SASL/TLS-
terminated brokers) gain an explicit options.specs.<label>.server
override carrying the actual test dial target instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…aders

routes[].with.headers could carry a bare-hostname :authority with no
schema-level check, silently violating the repo-wide invariant that every
HttpBeginEx producer sets an explicit port for sys:tcp_client's dynamic
dial-target resolution. Add properties entries for :authority (port-pattern),
:scheme (http/https enum), and :path (required) alongside the existing
patternProperties catch-all, and migrate every fixture accordingly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…a, prove via IT

Add the same options.specs.<label>.security schema block already present in
binding-openapi/binding-asyncapi/binding-mcp-openapi, closing a schema/adapter
parity gap (the generator-side support already existed but was unreachable
because the schema rejected the property). Add a proxy.guarded.yaml fixture
and shouldCreatePetWhenAuthorized IT proving the full chain (schema -> adapter
-> generator -> runtime dispatch -> guard verification -> success) at the
network level, matching how sibling bindings prove the same feature.

shouldRejectListPetsWhenUnauthorized is added but @ignore'd: the underlying
RESET-propagation on guard denial is confirmed correct end-to-end via direct
tracing (production code, JDWP breakpoints, k3po test-support internals), but
k3po reports a bare, message-less AssertionError for this composite-forwarded
rejection instead of a normal script mismatch or "connect aborted" match, and
the failure point could not be located even via exception/method breakpoints
in the sole test JVM -- narrowed to likely a Surefire/Failsafe fork-boundary
artifact rather than a script or production defect. Left in place, ignored,
for whoever picks up the k3po/Surefire interaction next.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
…g-consistency-65bxs2

Reconciles our shared OpenapiGuardResolver refactor (binding-mcp-openapi's
guard resolution moved off its own guardedRefs/resolveAlternative) with
develop's concurrently-landed #2105, which added operator-declared guarded:
composition (combineGuarded) on top of the pre-refactor code shape. Keeps
combineGuarded (genuinely new behavior) wired onto the shared resolver's
output instead of the removed local methods.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
claude added 8 commits July 10, 2026 17:53
Unreachable via YAML (the schema only declares tls/http/specs under
options), never populated by OpenapiOptionsConfigAdapter.adaptFromJson,
and never read by any generator. Leftover from before route-level
when.servers[] dispatch replaced it. Found while auditing remaining
options.* abstraction leaks after #2079's server/security cleanup
(tracked in #2113).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GkL1aVsaRHSPe4dCfd7kWK
injectMqttRoute used the specification-level compositeId for the
subscribe ("receive") route instead of the operation-level one,
unlike the publish ("send") branch just above it. The composite/mqtt
publish.and.subscribe fixtures also hardcoded a stale compositeId
bit layout that predates the serverIndex field on AsyncapiCompositeId,
so resolveOperation/resolveSpecification never matched and
AsyncapiServerIT's mqtt scenarios failed deterministically on every
run, not due to a k3po script race as previously suspected.
… new layout

The prior fix updated composite/mqtt/publish.and.subscribe/client.rpt and
asyncapi/mqtt/publish.and.subscribe/server.rpt to the corrected compositeId
bit layout but missed their respective siblings, breaking AsyncapiMqttIT
(pairs asyncapi/mqtt client+server against each other with no engine) via a
compositeId mismatch between that server.rpt and its still-stale client.rpt.

asyncapi/mqtt/publish.and.subscribe/client.rpt is also paired with
composite/mqtt/publish.and.subscribe/server.rpt for AsyncapiClientIT, which
exercises the client-side (kind: client) composite generator. That generator
has no per-operation compositeId assignment at all (confirmed by inspection
of AsyncapiClientGenerator), so the value is a fixture-internal match only,
not something asserted against production-computed output — both files can
move to the new encoding together without affecting that IT.
…d connect

shouldRejectListPetsWhenUnauthorized failed with a bare java.lang.AssertionError
during EngineRule teardown (Engine.close() -> Target.close() ->
doSyntheticReset), not during the actual test body -- the assertion only
threw with -ea (forked Surefire/Failsafe JVMs get -ea via argLine), so
forkCount=0 masked it, which had misled prior investigation. The real trace
(visible with -DtrimStackTrace=false, which Failsafe otherwise trims away)
showed OpenapiStream.onOpenapiReset asserting on a synthetic teardown-time
reset (sequence=Long.MAX_VALUE sentinel from Target.doSyntheticReset).

Root cause: EngineWorker.handleBeginInitial registers a stream's handler in
throttles[replyId] as soon as the initial BEGIN is accepted, in anticipation
of the reply direction opening later. When a guard denies the request before
any reply is ever sent, OpenapiStream never reaches doOpenapiBegin (which is
the only place that would later trigger a throttles[] removal via END/ABORT
on the reply). onCompositeReset only called delegate.doOpenapiReset (closes
the initial), never doOpenapiAbort (the reply side), so the throttles[]
registration was never cleaned up -- it leaked until engine shutdown, where
the teardown broadcast reset finally reached the stale handler and its
invariant assertions (written for real protocol resets, not the teardown
sentinel) failed. This is a genuine resource leak on every denied proxy
connection, not just a test artifact, since production JVMs run without -ea
and so never surface it.

Fix mirrors the existing pattern in KafkaMergedFactory.
doMergedReplyAbortIfNecessary: doOpenapiAbort now calls
context.detachSender(replyId) when the reply was never opened, and
onCompositeReset now calls doOpenapiAbort alongside doOpenapiReset so a
composite-forwarded denial closes both directions.
…tions.tcp

d7d9d91 removed the options.tcp escape hatch for kind: client openapi/
asyncapi bindings in favor of options.specs.<label>.server, and migrated
every fixture under specs/ accordingly, but missed the three examples/
configs that also declared options.tcp (asyncapi.mqtt.proxy,
asyncapi.sse.proxy, openapi.proxy). Since their upstream doc's own
declared servers don't match the actual docker-compose backend targets,
each gets an explicit server: override carrying the real dial target,
mirroring the SASL/TLS fixture migration pattern from that commit.

Without this, all three fail JSON schema validation on startup
("additionalProperties: false" rejects tcp), which is why their CI
example smoke tests were failing.
…ination to configured backend

d7d9d91 migrated openapi/asyncapi kind: client to exit through the
engine-native sys:tcp_client binding, relying on TcpBindingConfig's
dynamic ProxyBeginEx resolution. For HTTP-based clients (openapi,
asyncapi http/sse), OpenapiClientFactory/AsyncapiClientFactory relay
the :authority header from the *original inbound request* unmodified,
so sys:tcp_client dials whatever host the external client sent rather
than the configured backend. When that host happens to be Zilla's own
public address (a realistic case: the doc's declared servers: entry is
often the gateway's own address), the outbound leg loops back into
Zilla itself, re-entering the server binding repeatedly until a
maximumHeadersSize limit trips and the connection fails with 431.

Fix: apply an explicit :authority override on http_client0, sourced
from the same resolveServer()/doc-declared-server resolution already
used for scheme/path resolution, via a new plain-String override(String,
String) overload on HttpOptionsConfigBuilder (the existing overload
takes String8FW/String16FW from binding-http's unexported internal.types
package, unusable from other modules' composite generators).

For asyncapi's mqtt kind: client, sys:tcp_client cannot work at all:
MqttClientFactory never constructs a ProxyBeginEx (unlike KafkaClient*,
which supplies its own dynamic resolution from configured bootstrap
servers), so the connection has no destination to resolve and hangs.
Restored a dedicated, statically-configured tcp client for the plain
mqtt path (mirroring the pre-d7d9d918 behavior and the still-working
kafka_client0 pattern), sourced from the same resolveServer()/doc
fallback. The mqtts (TLS) path is left unchanged as a follow-up item
since it isn't exercised by any current example or test.

Verified against examples/openapi.proxy, examples/asyncapi.mqtt.proxy,
and examples/asyncapi.sse.proxy end-to-end via their .github/test.sh
smoke tests, and via full `mvnw verify` on binding-http, binding-openapi,
binding-asyncapi, binding-openapi-asyncapi, and binding-mcp-openapi with
no regressions.
…le server, matching http/kafka

d7d9d91 migrated every client protocol's exit to the engine-native
sys:tcp_client binding, which resolves its outbound destination
dynamically from a ProxyBeginEx on the initiating stream. HTTP-based
clients get this indirectly (an :authority override, fixed in the
previous commit); KafkaClient*Factory builds its own ProxyBeginEx from
configured bootstrap servers. MqttClientFactory did neither — it always
sent EMPTY_OCTETS, so sys:tcp_client had no destination to resolve at
all and every mqtt kind: client connection silently hung.

Add options.server (a URI string, e.g. mqtt://host:port) to
MqttOptionsConfig, mirroring the openapi/asyncapi options.specs.<label>.
server convention already established in this PR — accepted for both
kind: server and kind: client, resolved once into serverHost/serverPort
on MqttBindingConfig at bind time. MqttClientFactory now builds a
ProxyBeginEx from it in doNetworkBegin (INET address + AUTHORITY info,
identical construction to HttpClientFactory/KafkaClient*Factory), only
when a server is configured — otherwise behavior is unchanged.

AsyncapiClientGenerator.injectMqtt/injectMqtts now populate this option
from the same resolveServer()/doc-declared-server resolution already
used for scheme detection, for both the plain and TLS-secured mqtt
paths, replacing the previous session's standalone tcp_client0 binding
(which sidestepped sys:tcp_client rather than fixing why it didn't
work for mqtt). Also recognizes mqtt+secure as an alias for mqtts in
both the doc-protocol dispatch map and the secure-scheme list.

New binding-mqtt IT (ConnectionIT#shouldResolveConfiguredServer) proves
MqttClientFactory constructs the correct ProxyBeginEx from a configured
server, confirmed failing beforehand (EMPTY_OCTETS, no extension) and
passing after. Full mvnw verify green on binding-http, binding-mqtt,
binding-openapi, binding-asyncapi, binding-openapi-asyncapi, and
binding-mcp-openapi; examples/asyncapi.mqtt.proxy,
examples/openapi.proxy, and examples/asyncapi.sse.proxy all pass their
.github/test.sh smoke tests end-to-end against a locally built image.
Pulls in upstream fixes for the sandbox trust-store override (#2112) and
IPv6 unavailability (#2111) that this branch previously worked around
manually, plus new k3po reset-extension matching support (#2110, #2115)
and a vault entry resolution fix (#2114).
claude added 2 commits July 11, 2026 00:14
…health

Zilla started racing ahead of Kafka's own readiness (no depends_on),
so its Kafka cache-client bootstrap could fail once at startup and
never retry (binding-kafka's cache bootstrap is a one-shot stream
with no reconnect, tracked separately in #2116), leaving every
GET /pets hanging forever. Reproduced locally ~1 in 4-5 fresh
container starts; 10/10 clean after adding depends_on: service_healthy
on kafka, matching the pattern already used by kafka-init/kafka-ui in
the same compose.yaml.
…amples

Extends the same depends_on: kafka: condition: service_healthy fix
applied to asyncapi.http.kafka.proxy to the remaining 17 kafka-based
examples, none of which gated zilla's container start on kafka being
healthy. Same startup race (binding-kafka's cache bootstrap has no
retry, see #2116) applies to all of them equally, just with different
odds of tripping in CI.

Validated all 18 compose.yaml files with `docker compose config`.
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.

Split servers (path routing) from server (deployment target) on openapi/asyncapi client/server kinds

2 participants