asyncapi / saunter

Saunter is a code-first AsyncAPI documentation generator for dotnet.
https://www.asyncapi.com/
MIT License
204 stars 57 forks source link

Error: Maximum call stack size exceeded #123

Closed Anaster666 closed 2 years ago

Anaster666 commented 3 years ago

Good morning,

I have a DDD project in .netCore in differents projects. I have configured the asyncApi and it works because the annotations are in the controller. But when I add this annotations in "Application" shape and modify the assembly taking one class of all the project I have this error:

Error: Maximum call stack size exceeded

I have this structure:

StartUp:

(...)
options.AssemblyMarkerTypes = new[] { typeof(MotorApplication) };  //this is one of the differents classes in the project application
(...)

ProjectApplication:

[AsyncApi]
    public class SyncMotor : DomainEventHandler<MotorDomainEvent>
    {

        public SyncMotor ()
        {
        }

        [Channel("Automotion/v1/MotorDocuments/Sync", BindingsRef = "service-amqp-binding")]
        [PublishOperation(typeof(IntegrationEvent), Summary = "")]
        public override Task Handle(MotorDomainEvent notification, CancellationToken cancellationToken)
        {
        }
    }

Thanks!!!

m-wild commented 3 years ago

Hmmm 🤔 does your IntegrationEvent have a circular reference? Can you confirm which version of Saunter you are using?

Anaster666 commented 3 years ago

Hiii!!

I have detect the problem, is the class Exception of .netCore. If the class have one attribute of this class I will have the error of "maximum call stack".

I send you my test:

`
[AsyncApi] public class SyncDocumentIntegrationEventWhenUserPictureProfileDeletedDomainEventHandler : DomainEventHandler {

    private readonly IIntegrationEventBus _integrationEventBus;

    public SyncDocumentIntegrationEventWhenUserPictureProfileDeletedDomainEventHandler(IIntegrationEventBus integrationEventBus)
    {
        _integrationEventBus = integrationEventBus;
    }

    [Channel("BArchive/v1/BusinessDocuments/DeleteUserFile", BindingsRef = "service-amqp-binding")]
    [PublishOperation(typeof(HolaClass), Summary = "Inform about user picture profile is deleted.")]
    public override Task Handle(UserPictureProfileDeletedDomainEvent notification, CancellationToken cancellationToken)
    {
        return Task.CompletedTask;
    }
}

public class HolaClass
{
    public int holaaa { get; set; }
    public Exception ex { get; set; }

    public HolaClass(int userId) 
    {
    }

}`

The version is 0.8.0

Thanks for the help!

m-wild commented 2 years ago

Just had a deeper look into this. From your test case the asyncapi.json document is being generated correctly, but the AsyncAPI UI is unable to render it.

As a minimal example the following will produce the Maximum call stack size exceeded error.

asyncapi: 2.2.0
info:
  title: Streetlights API
  version: 1.0.0
channels:
  publish/light/measured:
    publish:
      operationId: MeasureLight
      message:
        payload:
          $ref: '#/components/schemas/lightMeasuredEvent'
        name: lightMeasuredEvent
components:
  schemas:
    lightMeasuredEvent:
      id: lightMeasuredEvent
      type: object
      properties:
        ex:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/exception'
    exception:
      id: exception
      type: object
      properties:
        Message:
          type: string
        InnerException:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/exception'  # <--- if we remove this self-reference, the UI renders fine.

I will raise this issue with the asyncapi team.

m-wild commented 2 years ago
m-wild commented 2 years ago

This has been fixed by the asyncapi team and updated in Saunter #144

m-wild commented 2 years ago

Fixed in v0.10.0 https://www.nuget.org/packages/Saunter/0.10.0