Skip to content

Commit

Permalink
hookup payload deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualBean committed May 28, 2024
1 parent 8634d7a commit bf07d1a
Show file tree
Hide file tree
Showing 26 changed files with 54 additions and 40 deletions.
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/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
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/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
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
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
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
9 changes: 3 additions & 6 deletions src/LEGO.AsyncAPI.Readers/V2/AsyncApiMessageDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

namespace LEGO.AsyncAPI.Readers
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Extensions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Readers.ParseNodes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;


internal static partial class AsyncApiV2Deserializer
{
Expand Down Expand Up @@ -97,7 +94,7 @@ private static IAsyncApiMessagePayload LoadPayload(ParseNode n, string format)
case var _ when SupportedJsonSchemaFormats.Where(s => format.StartsWith(s)).Any():
return new AsyncApiJsonSchemaPayload(AsyncApiSchemaDeserializer.LoadSchema(n));
case var _ when SupportedAvroSchemaFormats.Where(s => format.StartsWith(s)).Any():
return new AsyncApiAvroSchemaPayload();
return new AsyncApiAvroSchemaPayload(AsyncApiAvroSchemaDeserializer.LoadSchema(n));
default:
var supportedFormats = SupportedJsonSchemaFormats.Concat(SupportedAvroSchemaFormats);
throw new AsyncApiException($"'Could not deserialize Payload. Supported formats are {string.Join(", ", supportedFormats)}");
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI.Readers/V2/AsyncApiV2VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AsyncApiV2VersionService(AsyncApiDiagnostic diagnostic)
[typeof(AsyncApiParameter)] = AsyncApiV2Deserializer.LoadParameter,
[typeof(AsyncApiSchema)] = AsyncApiSchemaDeserializer.LoadSchema,
[typeof(AvroSchema)] = AsyncApiAvroSchemaDeserializer.LoadSchema,
[typeof(AsyncApiJsonSchemaPayload)] = AsyncApiV2Deserializer.LoadJsonSchemaPayload, // #ToFix how do we get the schemaFormat?!
[typeof(AsyncApiJsonSchemaPayload)] = AsyncApiV2Deserializer.LoadJsonSchemaPayload,
[typeof(AsyncApiAvroSchemaPayload)] = AsyncApiV2Deserializer.LoadAvroPayload,
[typeof(AsyncApiSecurityRequirement)] = AsyncApiV2Deserializer.LoadSecurityRequirement,
[typeof(AsyncApiSecurityScheme)] = AsyncApiV2Deserializer.LoadSecurityScheme,
Expand Down
41 changes: 39 additions & 2 deletions src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,52 @@

namespace LEGO.AsyncAPI.Models
{
using System;
using System.Collections.Generic;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

public class AsyncApiAvroSchemaPayload : IAsyncApiMessagePayload
{
private AvroSchema schema;

public AsyncApiAvroSchemaPayload()
{
this.schema = new AvroSchema();
}

public AsyncApiAvroSchemaPayload(AvroSchema schema)
{
this.schema = schema;
}

/// <summary>
/// The type of the schema. See <a href="https://avro.apache.org/docs/1.9.0/spec.html#schema_primitive">Avro Schema Types</a>.
/// </summary>
public AvroSchemaType Type { get => this.schema.Type; set => this.schema.Type = value; }

/// <summary>
/// The name of the schema. Required for named types (e.g., record, enum, fixed). See <a href="https://avro.apache.org/docs/1.9.0/spec.html#names">Avro Names</a>.
/// </summary>
public string Name { get => this.schema.Name; set => this.schema.Name = value; }

/// <summary>
/// The namespace of the schema. Useful for named types to avoid name conflicts.
/// </summary>
public string? Namespace { get => this.schema.Namespace; set => this.schema.Namespace = value; }

Check warning on line 36 in src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 36 in src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Documentation for the schema.
/// </summary>
public string? Doc { get => this.schema.Doc; set => this.schema.Doc = value; }

Check warning on line 41 in src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 41 in src/LEGO.AsyncAPI/Models/AsyncApiAvroSchemaPayload.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// The list of fields in the schema.
/// </summary>
public IList<AvroField> Fields { get => this.schema.Fields; set => this.schema.Fields = value; }

public void SerializeV2(IAsyncApiWriter writer)
{
throw new NotImplementedException();
this.schema.SerializeV2(writer);
}
}
}
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Models
{
using LEGO.AsyncAPI.Writers;
using System.Runtime.CompilerServices;

public class AvroPrimitive : AvroFieldType
{
Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Models
{
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Models.Interfaces;
using LEGO.AsyncAPI.Writers;

Expand Down
1 change: 0 additions & 1 deletion src/LEGO.AsyncAPI/Models/Avro/AvroSchemaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LEGO.AsyncAPI.Models
{
using System;
using LEGO.AsyncAPI.Attributes;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LEGO.AsyncAPI.Validation.Rules
{
using System.Linq;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Validations;
using System.Linq;

[AsyncApiRule]
public static class AsyncApiOAuthFlowRules
Expand Down
2 changes: 1 addition & 1 deletion src/LEGO.AsyncAPI/Writers/AsyncApiWriterException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace LEGO.AsyncAPI.Writers
{
using LEGO.AsyncAPI.Exceptions;
using System;
using LEGO.AsyncAPI.Exceptions;

public class AsyncApiWriterException : AsyncApiException
{
Expand Down
2 changes: 1 addition & 1 deletion test/LEGO.AsyncAPI.Tests/AsyncApiDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LEGO.AsyncAPI.Tests
{
using System;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
using System;

internal class AsyncApiDocumentBuilder
{
Expand Down
1 change: 0 additions & 1 deletion test/LEGO.AsyncAPI.Tests/AsyncApiDocumentV2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Tests
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using FluentAssertions;
Expand Down
1 change: 0 additions & 1 deletion test/LEGO.AsyncAPI.Tests/AsyncApiReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace LEGO.AsyncAPI.Tests
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using LEGO.AsyncAPI.Exceptions;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Models.Interfaces;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Tests.Bindings
{
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using LEGO.AsyncAPI.Bindings;
using LEGO.AsyncAPI.Models;
Expand Down
1 change: 0 additions & 1 deletion test/LEGO.AsyncAPI.Tests/FluentAssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Tests
{
using System;
using System.IO;
using FluentAssertions;
using FluentAssertions.Primitives;
using NUnit.Framework;
Expand Down
5 changes: 2 additions & 3 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiAnyTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) The LEGO Group. All rights reserved.

using LEGO.AsyncAPI.Models;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using LEGO.AsyncAPI.Models;
using NUnit.Framework;

namespace LEGO.AsyncAPI.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LEGO.AsyncAPI.Tests.Models
{
using System;
using System.Globalization;
using System.IO;
using FluentAssertions;
using LEGO.AsyncAPI.Bindings.Http;
Expand Down
3 changes: 1 addition & 2 deletions test/LEGO.AsyncAPI.Tests/Models/AsyncApiReference_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace LEGO.AsyncAPI.Tests
{
using System.Linq;
using FluentAssertions;
using FluentAssertions.Primitives;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using NUnit.Framework;
using System.Linq;

public class AsyncApiReference_Should : TestBase
{
Expand Down
1 change: 0 additions & 1 deletion test/LEGO.AsyncAPI.Tests/Models/AsyncApiSchema_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace LEGO.AsyncAPI.Tests.Models
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using FluentAssertions;
using LEGO.AsyncAPI.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace LEGO.AsyncAPI.Tests.Writers
{
using System.IO;
using LEGO.AsyncAPI.Writers;
using NUnit.Framework;
using System;
using System.IO;

internal class AsyncApiYamlWriterTests : TestBase
{
Expand Down

0 comments on commit bf07d1a

Please sign in to comment.