asyncapi / modelina

A library for generating typed models based on inputs such as AsyncAPI, OpenAPI, and JSON Schema documents with high customization
https://modelina.org
Apache License 2.0
301 stars 175 forks source link

generator should be able to generate generic types #194

Closed czlowiek488 closed 8 months ago

czlowiek488 commented 3 years ago

Context

I have specification written like below.

components:
  schemas:
    Envelope:      
      $id: Envelope
      description: "Envelope shared between messages"
      type: object
      required: [event, eventId]
      properties:
        eventId:
          type: string
        event:
          $id: Event
          type: object
messages:
  project.Created:
    payload:
      $id: MessageProjectCreated
      allOf:
        - $ref: "#/components/schemas/Envelope"
        - type: object
          required: [event]
          properties:
            eventName:
              const: "tms.event.project.created"
            event:
              type: object
              $id: EventProjectCreated
              required: [project]
              properties:
                project:
                  type: object

this is generating interface like this

export interface MessageProjectCreated {
    eventId: string;
    event: EventProjectCreated;
    eventName: "tms.event.project.created";
}

Reason#1

I have few events on event bus which are not coming from specification, but they are using Envelope from specification. Specifcation tells what events are send by my client, but I sometimes send my own events to the same event bus. For them I have to write my own Envelope and if Envelope will be changed in specification I will not be able to see differences.

Reason#2

In generic event handler I do not know which event is inside Envelope, it can be literally everything even an empty object in my test scenario.

Description

I would like to generate something like here for each $ref used in specs.

export interface Envelope<T> {
    eventId: string;
    event: T;
}

export interface MessageProjectCreated extends Envelope<EventProjectCreated> {
   eventName: tms.event.project.created;
 };

and I would be able to do something like

export const genericEventHandler = (event: Envelope<any>) => {...};
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping: It will be closed in 60 days if no further activity occurs. To unstale this issue, add a comment with detailed explanation. Thank you for your contributions :heart:

jonaslagoni commented 3 years ago

Still relevant.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity :sleeping:

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience :heart:

AnimeshKumar923 commented 8 months ago

still relevant? @jonaslagoni