flamewow / nestjs-asyncapi

NestJS AsyncAPI module - generate documentation of your event-based services using decorators
MIT License
197 stars 33 forks source link

Option to define the payload type (i.e array) #486

Open PatrickHallek opened 1 year ago

PatrickHallek commented 1 year ago

I have interfaces that respond with an array of dto's instead of a single object.

It would be nice if I could somehow define the array type like this:

@AsyncApiPub({
    channel: 'example',
    message: [
        {
            payload: ExampleDto,
            isArray: true,
        },
    ],
})

If this feature is currently available, it would be nice if the documentation could be updated accordingly. Besides that, awesome package and thanks for your work, I really appreciate it!

github-actions[bot] commented 1 year ago

Hello! Thank you for filing an issue.

If this is a bug report, please include relevant logs to help us debug the problem.

molfar808 commented 1 year ago

Some more info on what i've tried. We have some POJO (ExampleDto). Gateway function that receives/emits payload events as array: ExampleDto[]. I've tried to around ExampleDto with square brackets like i used to do with OpenAPI documentation:

@AsyncApiPub({
    channel: 'example',
    message: [
        {
            payload: [ExampleDto],
        },
    ],
})

But with no luck - Error: Input is not a corrent AsyncAPI document so it cannot be processed.

I ended up with "payload: Array\<ExampleDto>", but in generated doc there was no information about my Dto - it was simply showed as "Array" with an example of "{}".

So it would be nice if format "[ExampleDto]" or additional parameter "isArray: true" (like @PatrickHallek proposed) were supported.