diff --git a/Saunter.sln b/Saunter.sln index 038ce2f..57b58be 100644 --- a/Saunter.sln +++ b/Saunter.sln @@ -25,6 +25,7 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saunter.IntegrationTests.ReverseProxy", "test\Saunter.IntegrationTests.ReverseProxy\Saunter.IntegrationTests.ReverseProxy.csproj", "{7CD09B89-130A-41AF-ADAE-2166C4ED695B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Saunter.Tests.MarkerTypeTests", "test\Saunter.Tests.MarkerTypeTests\Saunter.Tests.MarkerTypeTests.csproj", "{02284473-6DE7-4EE0-8433-2AC295045549}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncAPI.Saunter.Attributes", "src\AsyncAPI.Saunter.Attributes\AsyncAPI.Saunter.Attributes.csproj", "{3591421D-0853-48C6-9A53-9E6B5D7E6B25}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "actions", "actions", "{D8CB9C0D-9605-457B-979F-C8994B20A926}" ProjectSection(SolutionItems) = preProject @@ -112,6 +113,18 @@ Global {02284473-6DE7-4EE0-8433-2AC295045549}.Release|x64.Build.0 = Release|Any CPU {02284473-6DE7-4EE0-8433-2AC295045549}.Release|x86.ActiveCfg = Release|Any CPU {02284473-6DE7-4EE0-8433-2AC295045549}.Release|x86.Build.0 = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|x64.ActiveCfg = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|x64.Build.0 = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|x86.ActiveCfg = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Debug|x86.Build.0 = Debug|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|Any CPU.Build.0 = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|x64.ActiveCfg = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|x64.Build.0 = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|x86.ActiveCfg = Release|Any CPU + {3591421D-0853-48C6-9A53-9E6B5D7E6B25}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -124,6 +137,7 @@ Global {02284473-6DE7-4EE0-8433-2AC295045549} = {6491E321-2D02-44AB-9116-D722FE169595} {69459F9D-DA73-4E84-8BA7-4CE03E2B7664} = {D8CB9C0D-9605-457B-979F-C8994B20A926} {E8FACA22-CFED-4710-89E4-D55F31BF96B3} = {D8CB9C0D-9605-457B-979F-C8994B20A926} + {3591421D-0853-48C6-9A53-9E6B5D7E6B25} = {28D4C365-FDED-49AE-A97D-36202E24A55A} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2F85D9DA-DBCF-4F13-8C42-5719F1469B2E} diff --git a/src/AsyncAPI.Saunter.Attributes/AsyncAPI.Saunter.Attributes.csproj b/src/AsyncAPI.Saunter.Attributes/AsyncAPI.Saunter.Attributes.csproj new file mode 100644 index 0000000..c44e002 --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/AsyncAPI.Saunter.Attributes.csproj @@ -0,0 +1,15 @@ + + + + AysncAPI.Saunter.Attributes + AysncAPI.Saunter.Attributes + netstandard2.0 + README.md + Provides the raw attributes which can be used to decorate code as being async api functions + + + + + + + diff --git a/src/AsyncAPI.Saunter.Attributes/AsyncApiAttribute.cs b/src/AsyncAPI.Saunter.Attributes/AsyncApiAttribute.cs new file mode 100644 index 0000000..b92b3ba --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/AsyncApiAttribute.cs @@ -0,0 +1,18 @@ +using System; + +namespace Saunter.Attributes +{ + /// + /// Marks a class or interface as containing asyncapi channels. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)] + public sealed class AsyncApiAttribute : Attribute + { + public string DocumentName { get; } + + public AsyncApiAttribute(string documentName = null) + { + DocumentName = documentName; + } + } +} diff --git a/src/AsyncAPI.Saunter.Attributes/ChannelAttribute.cs b/src/AsyncAPI.Saunter.Attributes/ChannelAttribute.cs new file mode 100644 index 0000000..de8939d --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/ChannelAttribute.cs @@ -0,0 +1,40 @@ +using System; + +namespace Saunter.Attributes +{ + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface)] + public class ChannelAttribute : Attribute + { + /// + /// The name of the channel. + /// Format depends on the underlying messaging protocol's conventions. + /// For example, amqp uses dot-separated paths 'light.measured'. + /// + public string Name { get; } + + /// + /// An optional description of this channel item. + /// CommonMark syntax can be used for rich text representation. + /// + public string Description { get; set; } + + /// + /// The name of a channel bindings item to reference. + /// The bindings must be added to components/channelBindings with the same name. + /// + public string BindingsRef { get; set; } + + /// + /// The servers on which this channel is available, specified as an optional unordered + /// list of names (string keys) of Server Objects defined in the Servers Object (a map). + /// If servers is absent or empty then this channel must be available on all servers + /// defined in the Servers Object. + /// + public string[] Servers { get; set; } + + public ChannelAttribute(string name) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + } + } +} diff --git a/src/AsyncAPI.Saunter.Attributes/ChannelParameterAttribute.cs b/src/AsyncAPI.Saunter.Attributes/ChannelParameterAttribute.cs new file mode 100644 index 0000000..aab0c95 --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/ChannelParameterAttribute.cs @@ -0,0 +1,22 @@ +using System; + +namespace Saunter.Attributes +{ + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)] + public class ChannelParameterAttribute : Attribute + { + public ChannelParameterAttribute(string name, Type type) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Type = type ?? throw new ArgumentNullException(nameof(type)); + } + + public string Name { get; } + + public Type Type { get; } + + public string Description { get; set; } + + public string Location { get; set; } + } +} diff --git a/src/AsyncAPI.Saunter.Attributes/MessageAttribute.cs b/src/AsyncAPI.Saunter.Attributes/MessageAttribute.cs new file mode 100644 index 0000000..86cf877 --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/MessageAttribute.cs @@ -0,0 +1,70 @@ +using System; + +namespace Saunter.Attributes +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class MessageAttribute : Attribute + { + public MessageAttribute(Type payloadType) + { + PayloadType = payloadType; + } + + public MessageAttribute(Type payloadType, params string[] tags) + { + PayloadType = payloadType; + Tags = tags; + } + + /// + /// The type to use to generate the message payload schema. + /// + public Type PayloadType { get; } + + /// + /// The type to use to generate the message headers schema. + /// + public Type HeadersType { get; set; } + + /// + /// A machine-friendly name for the message. + /// Defaults to the generated schemaId. + /// + public string Name { get; set; } + + /// + /// A human-friendly title for the message. + /// + public string Title { get; set; } + + /// + /// A short summary of what the message is about. + /// + public string Summary { get; set; } + + /// + /// A verbose explanation of the message. + /// CommonMark syntax can be used for rich text representation. + /// + public string Description { get; set; } + + /// + /// The name of a message bindings item to reference. + /// The bindings must be added to components/messageBindings with the same name. + /// + public string BindingsRef { get; set; } + + /// + /// Unique string used to identify the message. The id MUST be unique among all messages + /// described in the API. The messageId value is case-sensitive. Tools and libraries MAY + /// use the messageId to uniquely identify a message, therefore, it is RECOMMENDED to + /// follow common programming naming conventions. + /// + public string MessageId { get; set; } + + /// + /// A list of tags for API documentation control. Tags can be used for logical grouping of messages. + /// + public string[] Tags { get; } + } +} diff --git a/src/AsyncAPI.Saunter.Attributes/OperationAttribute.cs b/src/AsyncAPI.Saunter.Attributes/OperationAttribute.cs new file mode 100644 index 0000000..77f2662 --- /dev/null +++ b/src/AsyncAPI.Saunter.Attributes/OperationAttribute.cs @@ -0,0 +1,92 @@ +using System; + +namespace Saunter.Attributes +{ + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface)] + public abstract class OperationAttribute : Attribute + { + public OperationType OperationType { get; protected set; } + + public Type MessagePayloadType { get; protected set; } + + /// + /// A short summary of what the operation is about. + /// + public string Summary { get; set; } + + /// + /// Unique string used to identify the operation. + /// The id MUST be unique among all operations described in the API. + /// The operationId value is case-sensitive. + /// Tools and libraries MAY use the operationId to uniquely identify an operation, + /// therefore, it is RECOMMENDED to follow common programming naming conventions. + /// + public string OperationId { get; set; } + + /// + /// A verbose explanation of the operation. + /// CommonMark syntax can be used for rich text representation. + /// + public string Description { get; set; } + + /// + /// The name of an operation bindings item to reference. + /// The bindings must be added to components/operationBindings with the same name. + /// + public string BindingsRef { get; set; } + + /// + /// A list of tags for API documentation control. Tags can be used for logical grouping of operations. + /// + public string[] Tags { get; protected set; } + } + + public class PublishOperationAttribute : OperationAttribute + { + public PublishOperationAttribute(Type messagePayloadType, params string[] tags) + { + OperationType = OperationType.Publish; + MessagePayloadType = messagePayloadType; + Tags = tags; + } + public PublishOperationAttribute(Type messagePayloadType) + { + OperationType = OperationType.Publish; + MessagePayloadType = messagePayloadType; + } + + public PublishOperationAttribute() + { + OperationType = OperationType.Publish; + } + } + + public class SubscribeOperationAttribute : OperationAttribute + { + public SubscribeOperationAttribute(Type messagePayloadType, params string[] tags) + { + OperationType = OperationType.Publish; + MessagePayloadType = messagePayloadType; + Tags = tags; + } + + public SubscribeOperationAttribute(Type messagePayloadType) + { + OperationType = OperationType.Subscribe; + MessagePayloadType = messagePayloadType; + } + + public SubscribeOperationAttribute() + { + OperationType = OperationType.Subscribe; + } + } + + public enum OperationType + { + Publish, + Subscribe + } + + +} diff --git a/src/AsyncAPI.Saunter.Attributes/readme.md b/src/AsyncAPI.Saunter.Attributes/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/src/Saunter/Saunter.csproj b/src/Saunter/Saunter.csproj index a51a2e5..93a5e00 100644 --- a/src/Saunter/Saunter.csproj +++ b/src/Saunter/Saunter.csproj @@ -59,8 +59,12 @@ - - - + + + + + + +