asyncapi/saunter

Support isOneOf for messages with annotations/code first

Closed this issue · 2 comments

IME when publishing on a channel i publish many different message types, not seeing how that's possible to do here. i tried somethig like

[AsyncApi]
public class FuncCustomer
{

    // Creates a Channel
    [Channel("customers")] 
    [SubscribeOperation(
        typeof(CustomerAddressUpdateEventResource), 
        OperationId = "x", 
        Summary = "address update summary"
    )] 
    public void PublishAddressUpdate(
    
    )
    {
        
    }

    // Creates a Channel
    [Channel("customers")] 
    [SubscribeOperation(
        typeof(CustomerUpdateEventResource), 
        OperationId = "x", 
        Summary = "customer update summary"
    )] 
    public void PublishCustomerUpdate(

    )
    {
        
    }

}

and also trying to put the channel on the class (which doesn't work at all it seems) I was hoping the schema would figure out that it's the same operation and switch into a IsOneOf mode for the messages is this possible in some way?

totally aware i can do it in the prototype doc, but really looking to do it with annotations. kinda like a [MessageForOperation] attribute.

I found the way to get oneOf into the output. If you declare Channel and SubscribeOperation on the class declaration, and over your method declaration use the MessageAttribute and you'll get multiple messages under one channel's subscribe operation. So in your case, you should see multiple messages for one channel if you do

[AsyncApi]
[Channel("customers")] 
[SubscribeOperation()] 
public class FuncCustomer
{

    [Message(
        typeof(CustomerAddressUpdateEventResource), 
        MessageId = "x", 
        Summary = "address update summary"
    )] 
    public void PublishAddressUpdate(
    
    )
    {
        
    }

    [Message(
        typeof(CustomerUpdateEventResource), 
        MessageId = "x", 
        Summary = "customer update summary"
    )] 
    public void PublishCustomerUpdate(

    )
    {
        
    }

}

yup that works, closing...but would be nice to get example in docs