Closed AlexanderButs closed 3 years ago
Hi Alex, At the moment there are 2 options for describing channel parameters
Easy: Using the [ChannelParameterAttribute]
[Channel("foo.{id}")]
[ChannelParameter("id", typeof(int), Description = "The ID of the Foo")]
public Foo(int id) {}
channels:
foo.{id}:
parameters:
id:
description: "The ID of the Foo"
schema:
type: number
format: int32
Advanced: You could also do something like the below to automatically scan for parameters...
[Channel("foo.{id}")]
public Foo(int id) {}
public class ParameterFilter : IChannelItemFilter
{
public void Apply(ChannelItem channelItem, ChannelItemFilterContext context)
{
// here you could grab parameters from the method, or from the channel attribute...
if (context.Member is MethodInfo method)
{
var param = method.GetParameters();
foreach (var p in param)
{
// add each method parameter to the channel item
channelItem.Parameters[p.Name] = new Parameter
{
Schema = context.SchemaGenerator.Generate(p.GetType())
};
}
}
}
}
services.AddAsyncApiSchemaGeneration(options =>
{
options.ChannelItemFilters.Add(new ParameterFilter());
}
channels:
foo.{id}:
parameters:
id:
schema:
type: number
format: int32
Wow! Great! Super extensible library.
Thank you very much!
Glad to help. I will close this issue now, but feel free to re-open it if you have any problems 😃
Hey.
Thanks for such a great project. Looks promising.
Is there a way to describe channel name I publish events to as a pattern like "foo.{some_changing_pattern}"? Some context: I use queues in NATS to publish events and route them to proper websocket server to push to the client further. So I have a lot of queues with different names which follow one naming pattern.
Thanks in advance. Alex.