Possible to generate AsyncAPI docs when running FastStream manually, as a regular async function? #1823
-
Hi People, I'm a student doing an intern and I'm currently facing a problem. My endgoal will be code-first event API documentation with the help of FastStream. I want to leverage it's capabilities to generate AsyncAPI documents from code so we can build our event docs via pipelines. Therefore I'm aiming to replace aio-pika with FastStream in a rather large distributed system with multiple rather large microservices which communicate via RabbitMQ. For testing and exploration purposes I built a small application which consists of two services. One is just emitting events and the other is receiving events all via a default RabbitMQ broker. I figured that I'll probably need a way to run FastStream without it's CLI that's why I built it as shown in the tutorial. When I now try to run
I didn't find a way to generate an AsyncAPI document in other ways. Did I miss something or do you know a possible solution? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
@strock-dev Hi! Assuming that you wrote your import asyncio
app = None
def get_app():
return app
def create_app():
global app
app = FastStream(...)
async def main():
create_app()
await app.run() # blocking method
if __name__ == "__main__":
asyncio.run(main()) then you can write from .verifier import create_app, get_app
create_app()
app = get_app() and then run:
Hope that helps. If not, please let me know. |
Beta Was this translation helpful? Give feedback.
Thanks so much for your input! I didn't test your solution as I came up with a somewhat 'hacky' workaround for my problem. I imported
get_app_schema
and calledto_yaml()
on that schema. After that I just wrote that yaml into a file.Serving that yaml via FastStream worked for me. Another option is of course to use the AsyncAPI CLI to generate HTML from that file.
I'm unsure if I should mark your answer as correct, as I didn't test it by myself.