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

feat(message)!: apache avro payload support #170

Merged
merged 20 commits into from
Jun 3, 2024
Merged
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
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Bindings/AMQP/AMQPOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace LEGO.AsyncAPI.Bindings.AMQP
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;

Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Http/HttpMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
protected override FixedFieldMap<HttpMessageBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "headers", (a, n) => { a.Headers = JsonSchemaDeserializer.LoadSchema(n); } },
{ "headers", (a, n) => { a.Headers = AsyncApiSchemaDeserializer.LoadSchema(n); } },
};
}
}
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Http/HttpOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "type", (a, n) => { a.Type = n.GetScalarValue().GetEnumFromDisplayName<HttpOperationType>(); } },
{ "method", (a, n) => { a.Method = n.GetScalarValue(); } },
{ "query", (a, n) => { a.Query = JsonSchemaDeserializer.LoadSchema(n); } },
{ "query", (a, n) => { a.Query = AsyncApiSchemaDeserializer.LoadSchema(n); } },
};

public override string BindingKey => "http";
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Kafka/KafkaMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
protected override FixedFieldMap<KafkaMessageBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "key", (a, n) => { a.Key = JsonSchemaDeserializer.LoadSchema(n); } },
{ "key", (a, n) => { a.Key = AsyncApiSchemaDeserializer.LoadSchema(n); } },
{ "schemaIdLocation", (a, n) => { a.SchemaIdLocation = n.GetScalarValue(); } },
{ "schemaIdPayloadEncoding", (a, n) => { a.SchemaIdPayloadEncoding = n.GetScalarValue(); } },
{ "schemaLookupStrategy", (a, n) => { a.SchemaLookupStrategy = n.GetScalarValue(); } },
Expand Down
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI.Bindings/Kafka/KafkaOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class KafkaOperationBinding : OperationBinding<KafkaOperationBinding>
protected override FixedFieldMap<KafkaOperationBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "groupId", (a, n) => { a.GroupId = JsonSchemaDeserializer.LoadSchema(n); } },
{ "clientId", (a, n) => { a.ClientId = JsonSchemaDeserializer.LoadSchema(n); } },
{ "groupId", (a, n) => { a.GroupId = AsyncApiSchemaDeserializer.LoadSchema(n); } },
{ "clientId", (a, n) => { a.ClientId = AsyncApiSchemaDeserializer.LoadSchema(n); } },
};

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/MQTT/LastWill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LEGO.AsyncAPI.Bindings.MQTT
{
using System;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
using System;

public class LastWill : IAsyncApiElement
{
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/MQTT/MQTTMessageBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
protected override FixedFieldMap<MQTTMessageBinding> FixedFieldMap => new()
{
{ "payloadFormatIndicator", (a, n) => { a.PayloadFormatIndicator = n.GetIntegerValueOrDefault(); } },
{ "correlationData", (a, n) => { a.CorrelationData = JsonSchemaDeserializer.LoadSchema(n); } },
{ "correlationData", (a, n) => { a.CorrelationData = AsyncApiSchemaDeserializer.LoadSchema(n); } },
{ "contentType", (a, n) => { a.ContentType = n.GetScalarValue(); } },
{ "responseTopic", (a, n) => { a.ResponseTopic = n.GetScalarValue(); } },
};
Expand Down
3 changes: 0 additions & 3 deletions src/LEGO.AsyncAPI.Bindings/MQTT/MQTTOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace LEGO.AsyncAPI.Bindings.MQTT
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using LEGO.AsyncAPI.Readers.ParseNodes;
using LEGO.AsyncAPI.Writers;

Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Sns/Ordering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace LEGO.AsyncAPI.Bindings.Sns
public class Ordering : IAsyncApiExtensible
{
/// <summary>
/// What type of SNS Topic is this?
/// What type of SNS Topic is this?.
/// </summary>
public OrderingType Type { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Sns/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Statement : IAsyncApiExtensible
public StringOrStringList Principal { get; set; }

/// <summary>
/// The SNS permission being allowed or denied e.g. sns:Publish
/// The SNS permission being allowed or denied e.g. sns:Publish.
/// </summary>
public StringOrStringList Action { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI.Bindings/Sqs/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Queue : IAsyncApiExtensible
public string Name { get; set; }

/// <summary>
/// Is this a FIFO queue?
/// Is this a FIFO queue?.
/// </summary>
public bool FifoQueue { get; set; }

Expand Down Expand Up @@ -56,7 +56,7 @@ public class Queue : IAsyncApiExtensible
public RedrivePolicy RedrivePolicy { get; set; }

/// <summary>
/// The security policy for the SQS Queue
/// The security policy for the SQS Queue.
/// </summary>
public Policy Policy { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Sqs/RedrivePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace LEGO.AsyncAPI.Bindings.Sqs
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;
using System.Collections.Generic;

public class RedrivePolicy : IAsyncApiExtensible
{
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Sqs/SqsOperationBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LEGO.AsyncAPI.Bindings.Sqs
public class SqsOperationBinding : OperationBinding<SqsOperationBinding>
{
/// <summary>
/// Queue objects that are either the endpoint for an SNS Operation Binding Object, or the deadLetterQueue of the SQS Operation Binding Object
/// Queue objects that are either the endpoint for an SNS Operation Binding Object, or the deadLetterQueue of the SQS Operation Binding Object.
/// </summary>
public List<Queue> Queues { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Bindings/Sqs/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Statement : IAsyncApiExtensible
public StringOrStringList Principal { get; set; }

/// <summary>
/// The SNS permission being allowed or denied e.g. sns:Publish
/// The SNS permission being allowed or denied e.g. sns:Publish.
/// </summary>
public StringOrStringList Action { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class WebSocketsChannelBinding : ChannelBinding<WebSocketsChannelBinding>
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "method", (a, n) => { a.Method = n.GetScalarValue(); } },
{ "query", (a, n) => { a.Query = JsonSchemaDeserializer.LoadSchema(n); } },
{ "headers", (a, n) => { a.Headers = JsonSchemaDeserializer.LoadSchema(n); } },
{ "query", (a, n) => { a.Query = AsyncApiSchemaDeserializer.LoadSchema(n); } },
{ "headers", (a, n) => { a.Headers = AsyncApiSchemaDeserializer.LoadSchema(n); } },
};

public override void SerializeProperties(IAsyncApiWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace LEGO.AsyncAPI.Readers
using System;
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;

Expand Down Expand Up @@ -91,7 +90,10 @@ public override void Visit(AsyncApiOperation operation)
public override void Visit(AsyncApiMessage message)
{
this.ResolveObject(message.Headers, r => message.Headers = r);
this.ResolveObject(message.Payload, r => message.Payload = r);
if (message.Payload is AsyncApiJsonSchemaPayload)
{
this.ResolveObject(message.Payload as AsyncApiJsonSchemaPayload, r => message.Payload = r);
}
this.ResolveList(message.Traits);
this.ResolveObject(message.CorrelationId, r => message.CorrelationId = r);
this.ResolveObject(message.Bindings, r => message.Bindings = r);
Expand Down
2 changes: 0 additions & 2 deletions src/LEGO.AsyncAPI.Readers/AsyncApiJsonDocumentReader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) The LEGO Group. All rights reserved.

using System;

namespace LEGO.AsyncAPI.Readers
{
using System.Collections.Generic;
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI.Readers/AsyncApiTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Readers
{
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public AsyncApiUnsupportedSpecVersionException(string specificationVersion)
/// inner exception.
/// </summary>
/// <param name="specificationVersion">Version that caused this exception to be thrown.</param>
/// <param name="settings">The setting used for reading and writing</param>
/// <param name="settings">The setting used for reading and writing.</param>
/// <param name="innerException">Inner exception that caused this exception to be thrown.</param>
public AsyncApiUnsupportedSpecVersionException(string specificationVersion, Exception innerException)
: base(string.Format(CultureInfo.InvariantCulture, MessagePattern, specificationVersion), innerException)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace LEGO.AsyncAPI.Readers;

/// <summary>
/// Interface that provides method for reading external references.å
/// Interface that provides method for reading external references.å.
/// </summary>
public interface IAsyncApiExternalReferenceReader
{
Expand Down
8 changes: 8 additions & 0 deletions src/LEGO.AsyncAPI.Readers/ParseNodes/MapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ public override AsyncApiAny CreateAny()
return new AsyncApiAny(this.node);
}

public void ParseFields<T>(ref T parentInstance, IDictionary<string, Action<T, ParseNode>> fixedFields, IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
{
foreach (var propertyNode in this)
{
propertyNode.ParseField(parentInstance, fixedFields, patternFields);
}
}

private string ToScalarValue(JsonNode node)
{
var scalarNode = node is JsonValue value ? value : throw new AsyncApiException($"Expected scalar value");
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Readers/ParseNodes/PropertyNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void ParseField<T>(
else
{
this.Context.Diagnostic.Errors.Add(
new AsyncApiError("", $"{this.Name} is not a valid property at {this.Context.GetLocation()}"));
new AsyncApiError(string.Empty, $"{this.Name} is not a valid property at {this.Context.GetLocation()}"));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/LEGO.AsyncAPI.Readers/ParseNodes/ValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace LEGO.AsyncAPI.Readers.ParseNodes
{
using System;
using System.Text.Json.Nodes;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers.Exceptions;
using System;
using System.Text.Json.Nodes;

public class ValueNode : ParseNode
{
Expand Down
Loading
Loading