Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#199 Split attributes out so net standard can be targeted #203

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Saunter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>AysncAPI.Saunter.Attributes</PackageId>
<Title>AysncAPI.Saunter.Attributes</Title>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Description>Provides the raw attributes which can be used to decorate code as being async api functions</Description>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Saunter.Tests" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/AsyncAPI.Saunter.Attributes/AsyncApiAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Saunter.Attributes
{
/// <summary>
/// Marks a class or interface as containing asyncapi channels.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public sealed class AsyncApiAttribute : Attribute
{
public string DocumentName { get; }

public AsyncApiAttribute(string documentName = null)
{
DocumentName = documentName;
}
}
}
40 changes: 40 additions & 0 deletions src/AsyncAPI.Saunter.Attributes/ChannelAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace Saunter.Attributes
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface)]
public class ChannelAttribute : Attribute
{
/// <summary>
/// The name of the channel.
/// Format depends on the underlying messaging protocol's conventions.
/// For example, amqp uses dot-separated paths 'light.measured'.
/// </summary>
public string Name { get; }

/// <summary>
/// An optional description of this channel item.
/// CommonMark syntax can be used for rich text representation.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The name of a channel bindings item to reference.
/// The bindings must be added to components/channelBindings with the same name.
/// </summary>
public string BindingsRef { get; set; }

/// <summary>
/// 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.
/// </summary>
public string[] Servers { get; set; }

public ChannelAttribute(string name)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
}
}
}
22 changes: 22 additions & 0 deletions src/AsyncAPI.Saunter.Attributes/ChannelParameterAttribute.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
70 changes: 70 additions & 0 deletions src/AsyncAPI.Saunter.Attributes/MessageAttribute.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>
/// The type to use to generate the message payload schema.
/// </summary>
public Type PayloadType { get; }

/// <summary>
/// The type to use to generate the message headers schema.
/// </summary>
public Type HeadersType { get; set; }

/// <summary>
/// A machine-friendly name for the message.
/// Defaults to the generated schemaId.
/// </summary>
public string Name { get; set; }

/// <summary>
/// A human-friendly title for the message.
/// </summary>
public string Title { get; set; }

/// <summary>
/// A short summary of what the message is about.
/// </summary>
public string Summary { get; set; }

/// <summary>
/// A verbose explanation of the message.
/// CommonMark syntax can be used for rich text representation.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The name of a message bindings item to reference.
/// The bindings must be added to components/messageBindings with the same name.
/// </summary>
public string BindingsRef { get; set; }

/// <summary>
/// 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.
/// </summary>
public string MessageId { get; set; }

/// <summary>
/// A list of tags for API documentation control. Tags can be used for logical grouping of messages.
/// </summary>
public string[] Tags { get; }
}
}
92 changes: 92 additions & 0 deletions src/AsyncAPI.Saunter.Attributes/OperationAttribute.cs
Original file line number Diff line number Diff line change
@@ -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; }

/// <summary>
/// A short summary of what the operation is about.
/// </summary>
public string Summary { get; set; }

/// <summary>
/// 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.
/// </summary>
public string OperationId { get; set; }

/// <summary>
/// A verbose explanation of the operation.
/// CommonMark syntax can be used for rich text representation.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The name of an operation bindings item to reference.
/// The bindings must be added to components/operationBindings with the same name.
/// </summary>
public string BindingsRef { get; set; }

/// <summary>
/// A list of tags for API documentation control. Tags can be used for logical grouping of operations.
/// </summary>
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
}


}
Empty file.
10 changes: 7 additions & 3 deletions src/Saunter/Saunter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@
</None>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Saunter.Tests"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AsyncAPI.Saunter.Attributes\AsyncAPI.Saunter.Attributes.csproj" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Saunter.Tests"/>
</ItemGroup>

</Project>