- Notifications
You must be signed in to change notification settings - Fork41
NestJS AsyncAPI module - generate documentation of your event-based services using decorators
License
flamewow/nestjs-asyncapi
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
GenerateAsyncApi documentation (for event-based services, like websockets) in a similartonestjs/swagger fashion.
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
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.