Open Rikj000 opened 3 years ago
In theory this is supported. Currently you'd have a couple of options for generating the AsyncAPI components:
IDocumentFilter
to automatically scan the code for the MQTT AttributeRouting attributes.Option 2 would be ideal as an extension to saunter as an MQTT AttributeRouting support package.
Unfortunately I don't have any experience with MQTTnet or MQTT AttributeRouting, if you could provide a simple example project (or an existing open source project) using these packages, I am happy to spend some time trying to get it working, and prototype a package implementing option 2 above.
I'm not aware of any existing examples using MQTTnet and Saunter.
Saunter doesn't provide any message broker, but has support for documenting them by using bindings. We currently only have binding implemented for amqp, http, and Kafka, but I am happy to add MQTT. These have to be added to the document using filters today, autogenerating them from the MQTT AttributeRouting attributes (as above) would be ideal.
Option 2 would be ideal as an extension to saunter as an MQTT AttributeRouting support package.
This also sounds like the cleanest implementation to me!π However I'm unsure if I have enough knowledge of MQTT, AsyncAPI and C# Attributes on my own to make this happen..
Unfortunately I don't have any experience with MQTTnet or MQTT AttributeRouting, if you could provide a simple example project (or an existing open source project) using these packages, I am happy to spend some time trying to get it working, and prototype a package implementing option 2 above.
I just poured my current work into a de-branded example project and invited you as a collaborator, also added a quick readme page to quickly help find your way through the project:
Saunter-MQTTnet-AspNet5-AttributeRouting-ExampleProject
I'll continue to try and implement this during my working hours for as long as my boss allows me to work on it, however in my free time I won't have time to work on this, so I hope we can see this through in time! π
Managed to get Option 1
working! π
However the Channel name string conversion (Different for MQTTnet Attribute Routing
& Saunter
) is still HardCoded,
I will write up a conversion method and push it to the example project.
Feel free to reference my project in your Documentation or to include the conversion method in Saunter once I finished it up!
Thanks, I will take a look over the next few days.
Ok, there are a couple of issues with Option 2...
DocumentFilterContext
does not expose the ISchemaGenerator
-- easy fix from my side.We can either
MqttRouteTableFactory
MqttRouteTable
```csharp
public class MqttNetAspNetCoreAttributeRoutingDocumentFilter : IDocumentFilter
{
public void Apply(AsyncApiDocument document, DocumentFilterContext context)
{
var mqttRouteTableFactory = Type.GetType("MQTTnet.AspNetCore.AttributeRouting.MqttRouteTableFactory, MQTTnet.AspNetCore.AttributeRouting");
var mqttRouteTable = Type.GetType("MQTTnet.AspNetCore.AttributeRouting.MqttRouteTable, MQTTnet.AspNetCore.AttributeRouting");
var mqttRoute = Type.GetType("MQTTnet.AspNetCore.AttributeRouting.MqttRoute, MQTTnet.AspNetCore.AttributeRouting");
var mqttRouteTemplate = Type.GetType("MQTTnet.AspNetCore.AttributeRouting.RouteTemplate, MQTTnet.AspNetCore.AttributeRouting");
var mqttTemplateSegment = Type.GetType("MQTTnet.AspNetCore.AttributeRouting.TemplateSegment, MQTTnet.AspNetCore.AttributeRouting");
var create = mqttRouteTableFactory.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any,
new[] {typeof(IEnumerable
```csharp public class MqttNetAspNetCoreAttributeRoutingDocumentFilter : IDocumentFilter { private readonly MqttRouteTable _mqttRouteTable; public MqttNetAspNetCoreAttributeRoutingDocumentFilter(MqttRouteTable mqttRouteTable) { _mqttRouteTable = mqttRouteTable; } public void Apply(AsyncApiDocument document, DocumentFilterContext context) { foreach (var route in _mqttRouteTable.Routes) { // MQTTnet route templates are not uri safe, which is required by the asyncapi spec. var channelItemName = string.Join("/", route.Template.Segments.Select(s => s.IsCatchAll ? "#" : s.IsParameter ? "+" : s.Value)); var handler = route.Handler; var parameters = handler.GetParameters(); ISchema payload = null; if (parameters != null && parameters.Any()) { payload = context.SchemaGenerator.GenerateSchema(parameters.First().ParameterType, context.SchemaRepository); } document.Channels.Add(channelItemName, new ChannelItem { Publish = new Operation { OperationId = handler.Name, Summary = handler.GetXmlDocsSummary(), Message = new Message { Payload = payload, } } }); } } } ```
I will raise an issue on the MQTTnet.AspNetCore.AttributeRouting project.
I've been struggling to get
Saunter v0.3.1
to work in combination with:My project has these 2 MQTTnet libraries implemented successfully in ASP.NET 5 now. I tried to follow Saunters documentation to the letter too. However with MQTTnet there was no need for me to implement
MessageBus(Interface)
s orEvent
(model-like) classes.I can send/receive payloads from the MQTTnet.App client test application, however Saunter AsyncAPI Documentation generation keeps failing, the only thing I see hosted under
/asyncapi/ui/index.html
is the info defined innew AsyncApiDocument()
ofStartup.cs
.Which lead me to wondering:
Any help would be truly welcome!