event-catalog / eventcatalog

An open source documentation tool to bring discoverability to your event-driven architectures
https://eventcatalog.dev
MIT License
1.78k stars 151 forks source link

AsyncApi generator - service that is both consumer and producer not supported #318

Closed jelleVandendriessche closed 1 year ago

jelleVandendriessche commented 2 years ago

Have you read the Contributing Guidelines on issues?

Description

I have an API that is both consumer and producer of an event. But when using the generator it only fills in the producers field. The consumers fields is left empty.

Other events where the service is only a consumer work fine.

Steps to reproduce

  1. Create an asyapi.yaml that uses the same event as a publishers as a consumer
  2. Execute generate
asyncapi: 2.4.0
info:
  title: ResultsDataService
  version: 1.0.0
  description: Results API
servers:
  rabbitmq:
    url: localhost
    protocol: amqp
defaultContentType: application/json
channels:
  deliveries/deliveryevent:
    subscribe:
      operationId: NotifyDeliveryCreated
      summary: Inform when delivery is created.
      message:
        $ref: '#/components/messages/deliveryEvent'
  delivery-event:
    publish:
      operationId: DeliveryCreatedConsumer
      summary: Updates deliverymapfeatures using Delivery event
      message:
        payload:
          $ref: '#/components/schemas/deliveryEvent'
components:
  schemas:
    deliveryEvent:
      id: deliveryEvent
      type: object
      additionalProperties: false
      properties:
        eventType:
          type: string
        stampTime:
          type: string
          format: date-time
  messages:
    deliveryEvent:
      payload:
        $ref: '#/components/schemas/deliveryEvent'
      name: deliveryEvent

Expected behavior

The service is added both as a consumers as a producer.

---
name: deliveryEvent
summary: null
version: 1.0.0
producers:
    - ResultsDataService
consumers:
    - ResultsDataService
externalLinks: []
badges: []
---
<Mermaid />

<NodeGraph />

<Schema />

Actual behavior

---
name: deliveryEvent
summary: null
version: 1.0.0
producers:
    - ResultsDataService
consumers: []
externalLinks: []
badges: []
---
<Mermaid />

<NodeGraph />

<Schema />

Your environment

"@eventcatalog/core": "0.6.0",
"@eventcatalog/plugin-doc-generator-asyncapi": "^0.3.1"
"@eventcatalog/types": "0.4.0"
kennethaasan commented 1 year ago

I can confirm that this is an issue for us as well

michelgrootjans-conundra commented 1 year ago

I ran your example. It generated 2 events:

---
name: deliveryEvent
summary: null
version: 1.0.0
producers:
    - ResultsDataService
consumers: []
externalLinks: []
badges: []
---

<NodeGraph />

<Schema />
---
name: '<anonymous-message-2>'
summary: null
version: 1.0.0
producers: []
consumers:
    - ResultsDataService
externalLinks: []
badges: []
---

<NodeGraph />

<Schema />

As far as I understand it, this is because the DeliveryCreatedConsumer message doesn't have a name, so the AsyncAPI generator considers it a different event.

You could change your specification, to:

  delivery-event:
    publish:
      operationId: DeliveryCreatedConsumer
      summary: Updates deliverymapfeatures using Delivery event
      message:
        $ref: '#/components/messages/deliveryEvent'

The generator now realises it is the same message, but interprets it as a different version. So it generates:

events/deliveryEvent
├── index.md
├── schema.json
└── versioned
    └── 1.0.0
        ├── index.md
        └── schema.json

This is not the expected behaviour.

boyney123 commented 1 year ago

Thanks @jelleVandendriessche for raising the issue and others helping out.

I made a new test and fix for this and managed to get it working with your test AsyncAPI file you provided. @jelleVandendriessche when you get a chance you could test again when the package is released (Just doing that now).

boyney123 commented 1 year ago

Fix has gone out @eventcatalog/plugin-doc-generator-asyncapi version 0.3.2, let me know if it works OK, thanks again!

jelleVandendriessche commented 1 year ago

Works like a charm!

boyney123 commented 1 year ago

Awesome! Enjoy