asyncapi / generator

Use your AsyncAPI definition to generate literally anything. Markdown documentation, Node.js code, HTML documentation, anything!
https://asyncapi.com/docs/tools/generator
Apache License 2.0
764 stars 228 forks source link

Recursive model #620

Closed mflorczak closed 3 years ago

mflorczak commented 3 years ago

Describe the bug I want to create tree structure which each object has list of the same types.

How to Reproduce This is my schemas components image

It is recursive tree model image

And this is error image

Expected behavior As a user I want to be able to create recursive model eg. trees graphs etc.

github-actions[bot] commented 3 years ago

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

magicmatatjahu commented 3 years ago

@mflorczak Hi! Could you add more information like which template do you want to use?

Have in mind that some templates doesn't support specification with the circular references.

EDIT: Could you also add the given spec with circular refs as plain text in the comment, not as images?

mflorczak commented 3 years ago

Hello! I used java-spring-template

type: object
properties:
  id:
    type: integer
    format: int64
  name:
    type: string
  created:
    type: string
    format: date-time
  stamp:
    type: string
    format: date-time
  children:
    type: array
    items:
      $ref: "../async-consume.yaml#/components/schemas/NodeAdto"

channels:

  flexible-production:
    description: flexible production topic.
    publish:
      summary: Listens on shopfloor execution context topic.
      operationId: flp
      message:
        name: templatePointerMessage
        title: template with decoded name
        summary: template pointer message.
        contentType: application/json
        payload:
          $ref: '#/components/schemas/TemplatePointerAdto'

components:
  schemas:
    TemplatePointerAdto:
      $ref: './schemas/TemplatePointer.yaml'
    TemplateAdto:
      $ref: './schemas/Template.yaml'
    ProcessAdto:
      $ref: './schemas/Process.yaml'
    NodeAdto:
      $ref: './schemas/Node.yaml'
    NodeLinkAdto:
      $ref: './schemas/NodeLink.yaml'

type: object
description: template pointer.
events:
  - TEMPLATE_POINTER_CREATED
properties:
  itemId:
    type: string
  template:
    $ref: "../async-consume.yaml#/components/schemas/NodeAdto"
magicmatatjahu commented 3 years ago

Currently we support the circular refs in the spec, but not in every places (more info here). Generator can parse/validate your spec and pass it to the template. The given error is throw by this line https://github.com/asyncapi/java-spring-template/blob/master/filters/all.js#L101 Native JSON. stringify function doesn't support the circular refs, so it's not a problem with generator, but it's related with template itself. I will close the issue, and please continue the discussion here.

Also please don't cut the error, because this line:

image

is most important :P