docs: show grouping subscribers under the FastAPI OutboxRouter - #203
Merged
Merged
Conversation
Benchmark gate✅ gate passed
Gated (fails the build): |
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.
Refs #158.
Summary
#158 asked whether
faststream_outbox.fastapi.OutboxRoutershould forwardrouters=to the inner broker. It should not, and the capability it would provide already exists throughrouter.include_router(...). This PR documents and tests that path.Why not forward
routers=StreamRouter.include_routeraccepts a broker-level router, wraps each of its subscribers with the FastAPI compatibility decorator, then callsbroker.include_router. That is FastStream's documented "multiple routers" pattern for FastAPI.OutboxBroker(routers=...)just callsinclude_routersin the constructor, skipping that wrap. Under the FastAPI routerapply_types=False, so nothing injects arguments: a handler withd: str = Depends(dep)receives the rawOutboxMessageas its body and theDepends(...)object itself asd. No error, wrong values.routerseither.The two open questions in #158 are settled by observation on the
include_routerpath: nested subscribers belong to the same broker, so they start with it in the FastAPI lifespan, and their channels appear in the/asyncapidocument.Changes
docs/usage/fastapi.md: new "Grouping subscribers" section showing a plainfaststream_outbox.OutboxRouterincluded into the FastAPI router, plus the two shapes that do not work (nesting FastAPI routers raisesTypeError;router.broker.include_routerskips the bridge). Theroutersbullet under "What's intentionally not exposed" now gives the reason and points to the section.tests/test_fastapi.py:test_included_broker_router_subscriber_resolves_fastapi_depends(INVARIANT) checks thatDependsresolves in a nested subscriber and the channel is in the AsyncAPI document. Switching the include torouter.broker.include_router(sub)makes it fail.Checks
just lint-ci: passpytest --no-cov: 518 passed, 107 skipped (Postgres integration tests; not run locally, no SQL touched)just docs-build(mkdocs build --strict): pass