Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NestJS AsyncAPI module - generate documentation of your event-based services using decorators

License

NotificationsYou must be signed in to change notification settings

flamewow/nestjs-asyncapi

Repository files navigation

AsyncApi module forNest.

GenerateAsyncApi documentation (for event-based services, like websockets) in a similartonestjs/swagger fashion.

AsyncApi playground

Installation

full installation (with chromium)

$ npm i --save nestjs-asyncapi

nestjs-async api package doesn't require chromium (which is required by asyncapi lib), so u can skip chromiuminstallation by setting PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true environment variable.

$ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm i --save nestjs-asyncapi

Quick Start

Include AsyncApi initialization into your bootstrap function.

asyncfunctionbootstrap(){constapp=awaitNestFactory.create<NestExpressApplication>(AppModule);constasyncApiOptions=newAsyncApiDocumentBuilder().setTitle('Feline').setDescription('Feline server description here').setVersion('1.0').setDefaultContentType('application/json').addSecurity('user-password',{type:'userPassword'}).addServer('feline-ws',{url:'ws://localhost:3000',protocol:'socket.io',}).build();constasyncapiDocument=awaitAsyncApiModule.createDocument(app,asyncApiOptions);awaitAsyncApiModule.setup(docRelPath,app,asyncapiDocument);// other bootstrap procedures herereturnapp.listen(3000);}

AsyncApi module exploresControllers &WebSocketGateway by default.In most cases you won't need to add extra annotation,but if you need to define asyncApi operations in a class that's not a controller or gateway use theAsyncApi classdecorator.

Mark pub/sub methods viaAsyncApiPub orAsyncApiSub decorators

classCreateFelineDto{    @ApiProperty()demo:string;}@Controller()classDemoController{    @AsyncApiPub({channel:'create/feline',message:{payload:CreateFelineDto},})asynccreateFeline(){// logic here}    @AsyncApiSub({channel:'create/feline',message:{payload:CreateFelineDto},})asynccreateFeline(){// logic here}}

For more detailed examples please check outhttps://github.com/flamewow/nestjs-asyncapi/tree/main/sample sample app.

Do you use this library and like it? Don't be shy to give it a starongithub

About

NestJS AsyncAPI module - generate documentation of your event-based services using decorators

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp