Skip to content

Commit

Permalink
message- & operation traits
Browse files Browse the repository at this point in the history
plus minor formatting fixes across the solution
  • Loading branch information
VisualBean committed Jan 28, 2025
1 parent 124776b commit f922979
Show file tree
Hide file tree
Showing 45 changed files with 271 additions and 243 deletions.
30 changes: 15 additions & 15 deletions src/LEGO.AsyncAPI.Bindings/Sns/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ public static Condition Parse(ParseNode node)
switch (node)
{
case MapNode mapNode:
{
var conditionValues = new Dictionary<string, Dictionary<string, StringOrStringList>>();
foreach (var conditionNode in mapNode)
{
switch (conditionNode.Value)
var conditionValues = new Dictionary<string, Dictionary<string, StringOrStringList>>();
foreach (var conditionNode in mapNode)
{
case MapNode conditionValueNode:
conditionValues.Add(conditionNode.Name, new Dictionary<string, StringOrStringList>(conditionValueNode.Select(x =>
new KeyValuePair<string, StringOrStringList>(x.Name, StringOrStringList.Parse(x.Value)))
.ToDictionary(x => x.Key, x => x.Value)));
break;
default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
$"AWS condition values should be one or more key value pairs.");
switch (conditionNode.Value)
{
case MapNode conditionValueNode:
conditionValues.Add(conditionNode.Name, new Dictionary<string, StringOrStringList>(conditionValueNode.Select(x =>
new KeyValuePair<string, StringOrStringList>(x.Name, StringOrStringList.Parse(x.Value)))
.ToDictionary(x => x.Key, x => x.Value)));
break;
default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
$"AWS condition values should be one or more key value pairs.");
}
}
}

return new Condition(conditionValues);
}
return new Condition(conditionValues);
}

default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
Expand Down
24 changes: 13 additions & 11 deletions src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Bindings.Sns;

using System;
Expand Down Expand Up @@ -28,20 +30,20 @@ public static Principal Parse(ParseNode node)
return new PrincipalStar();

case MapNode mapNode:
{
var propertyNode = mapNode.First();
if (!IsValidPrincipalProperty(propertyNode.Name))
{
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
$"Node should contain a valid AWS principal property name.");
}
var propertyNode = mapNode.First();
if (!IsValidPrincipalProperty(propertyNode.Name))
{
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
$"Node should contain a valid AWS principal property name.");
}

var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value));
var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value));

return new PrincipalObject(principalValue);
}
return new PrincipalObject(principalValue);
}

default:
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
Expand Down
2 changes: 2 additions & 0 deletions src/LEGO.AsyncAPI.Bindings/Sns/PrincipalObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Bindings.Sns;

using System;
Expand Down
2 changes: 2 additions & 0 deletions src/LEGO.AsyncAPI.Bindings/Sns/PrincipalStar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Bindings.Sns;

using System;
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Sns/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Bindings.Sns
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Attributes;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

Expand Down
30 changes: 15 additions & 15 deletions src/LEGO.AsyncAPI.Bindings/Sqs/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ public static Condition Parse(ParseNode node)
switch (node)
{
case MapNode mapNode:
{
var conditionValues = new Dictionary<string, Dictionary<string, StringOrStringList>>();
foreach (var conditionNode in mapNode)
{
switch (conditionNode.Value)
var conditionValues = new Dictionary<string, Dictionary<string, StringOrStringList>>();
foreach (var conditionNode in mapNode)
{
case MapNode conditionValueNode:
conditionValues.Add(conditionNode.Name, new Dictionary<string, StringOrStringList>(conditionValueNode.Select(x =>
new KeyValuePair<string, StringOrStringList>(x.Name, StringOrStringList.Parse(x.Value)))
.ToDictionary(x => x.Key, x => x.Value)));
break;
default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
$"AWS condition values should be one or more key value pairs.");
switch (conditionNode.Value)
{
case MapNode conditionValueNode:
conditionValues.Add(conditionNode.Name, new Dictionary<string, StringOrStringList>(conditionValueNode.Select(x =>
new KeyValuePair<string, StringOrStringList>(x.Name, StringOrStringList.Parse(x.Value)))
.ToDictionary(x => x.Key, x => x.Value)));
break;
default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
$"AWS condition values should be one or more key value pairs.");
}
}
}

return new Condition(conditionValues);
}
return new Condition(conditionValues);
}

default:
throw new ArgumentException($"An error occured while parsing a {nameof(Condition)} node. " +
Expand Down
22 changes: 11 additions & 11 deletions src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public static Principal Parse(ParseNode node)
return new PrincipalStar();

case MapNode mapNode:
{
var propertyNode = mapNode.First();
if (!IsValidPrincipalProperty(propertyNode.Name))
{
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
$"Node should contain a valid AWS principal property name.");
}
var propertyNode = mapNode.First();
if (!IsValidPrincipalProperty(propertyNode.Name))
{
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
$"Node should contain a valid AWS principal property name.");
}

var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value));
var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value));

return new PrincipalObject(principalValue);
}
return new PrincipalObject(principalValue);
}

default:
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " +
Expand Down
2 changes: 2 additions & 0 deletions src/LEGO.AsyncAPI.Bindings/Sqs/PrincipalObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Bindings.Sqs;

using System;
Expand Down
2 changes: 2 additions & 0 deletions src/LEGO.AsyncAPI.Bindings/Sqs/PrincipalStar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

namespace LEGO.AsyncAPI.Bindings.Sqs;

using System;
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/Sqs/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace LEGO.AsyncAPI.Bindings.Sqs
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Attributes;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Readers/AsyncApiReaderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace LEGO.AsyncAPI.Readers
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.Interface;
using LEGO.AsyncAPI.Readers.Services;
using LEGO.AsyncAPI.Validations;

public enum ReferenceResolutionSetting
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Readers/Interface/IStreamLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Readers.Interface
{
using System;
using System.IO;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

public interface IStreamLoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ internal class AsyncApiRemoteReferenceCollector : AsyncApiVisitorBase

public AsyncApiRemoteReferenceCollector(
AsyncApiDocument currentDocument)
{
this.currentDocument = currentDocument;
}
{
this.currentDocument = currentDocument;
}
/// <summary>
/// List of all external references collected from AsyncApiDocument.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace LEGO.AsyncAPI.Readers
{
using System;
using System.Threading;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Avro.LogicalTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal static partial class AsyncApiV2Deserializer
{ "securitySchemes", (a, n) => a.SecuritySchemes = n.CreateMap(LoadSecurityScheme) },
{ "parameters", (a, n) => a.Parameters = n.CreateMap(LoadParameter) },
{ "correlationIds", (a, n) => a.CorrelationIds = n.CreateMap(LoadCorrelationId) },
{ "operationTraits", (a, n) => a.OperationTraits = n.CreateMapWithReference(ReferenceType.OperationTrait, LoadOperationTrait) },
{ "messageTraits", (a, n) => a.MessageTraits = n.CreateMapWithReference(ReferenceType.MessageTrait, LoadMessageTrait) },
{ "operationTraits", (a, n) => a.OperationTraits = n.CreateMap(LoadOperationTrait) },
{ "messageTraits", (a, n) => a.MessageTraits = n.CreateMap(LoadMessageTrait) },
{ "serverBindings", (a, n) => a.ServerBindings = n.CreateMapWithReference(ReferenceType.ServerBindings, LoadServerBindings) },
{ "channelBindings", (a, n) => a.ChannelBindings = n.CreateMapWithReference(ReferenceType.ChannelBindings, LoadChannelBindings) },
{ "operationBindings", (a, n) => a.OperationBindings = n.CreateMapWithReference(ReferenceType.OperationBindings, LoadOperationBindings) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static AsyncApiMessageTrait LoadMessageTrait(ParseNode node)

if (pointer != null)
{
return mapNode.GetReferencedObject<AsyncApiMessageTrait>(ReferenceType.MessageTrait, pointer);
return new AsyncApiMessageTraitReference(pointer);
}

var messageTrait = new AsyncApiMessageTrait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static AsyncApiOperationTrait LoadOperationTrait(ParseNode node)
var pointer = mapNode.GetReferencePointer();
if (pointer != null)
{
return mapNode.GetReferencedObject<AsyncApiOperationTrait>(ReferenceType.OperationTrait, pointer);
return new AsyncApiOperationTraitReference(pointer);
}

var operationTrait = new AsyncApiOperationTrait();
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Readers/YamlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static JsonValue ToJsonValue(this YamlScalarNode yaml, CultureInfo cultu
? JsonValue.Create(d)
: bool.TryParse(yaml.Value, out var b)
? JsonValue.Create(b)
: JsonValue.Create(yaml.Value) !;
: JsonValue.Create(yaml.Value)!;
case ScalarStyle.SingleQuoted:
case ScalarStyle.DoubleQuoted:
case ScalarStyle.Literal:
Expand Down
2 changes: 0 additions & 2 deletions src/LEGO.AsyncAPI/AsyncApiWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ public T ResolveReference<T>(string location)
return default;
}



private Uri ToLocationUrl(string location)
{
return new(location, UriKind.RelativeOrAbsolute);
Expand Down
12 changes: 4 additions & 8 deletions src/LEGO.AsyncAPI/Models/AsyncApiComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,9 @@ public void SerializeV2(IAsyncApiWriter writer)
this.OperationTraits,
(w, key, component) =>
{
if (component.Reference != null &&
component.Reference.Type == ReferenceType.OperationTrait &&
component.Reference.FragmentId == key)
if (component is AsyncApiOperationTraitReference reference)
{
component.SerializeV2WithoutReference(w);
reference.SerializeV2(w);
}
else
{
Expand All @@ -278,11 +276,9 @@ public void SerializeV2(IAsyncApiWriter writer)
this.MessageTraits,
(w, key, component) =>
{
if (component.Reference != null &&
component.Reference.Type == ReferenceType.MessageTrait &&
component.Reference.FragmentId == key)
if (component is AsyncApiMessageTraitReference reference)
{
component.SerializeV2WithoutReference(w);
reference.SerializeV2(w);
}
else
{
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI/Models/AsyncApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace LEGO.AsyncAPI.Models
using System.Collections.Generic;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
using LEGO.AsyncAPI.Services;

/// <summary>
/// This is the root document object for the API specification. It combines resource listing and API declaration together into one document.
Expand Down
Loading

0 comments on commit f922979

Please sign in to comment.