Skip to content

Commit

Permalink
fix serialize bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
yurvon-screamo committed Aug 8, 2024
1 parent 8d7b65e commit 66240f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Saunter/SharedKernel/AsyncApiDocumentSerializeCloner.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using LEGO.AsyncAPI;
using LEGO.AsyncAPI.Bindings;
using LEGO.AsyncAPI.Models;
using LEGO.AsyncAPI.Readers;
using Microsoft.Extensions.Logging;
using Saunter.SharedKernel.Interfaces;

namespace Saunter.SharedKernel
{
// This whole class is one huge crutch, it would be necessary to do manual mapping..
internal class AsyncApiDocumentSerializeCloner : IAsyncApiDocumentCloner
{
private readonly ILogger<AsyncApiDocumentSerializeCloner> _logger;
Expand All @@ -20,25 +20,20 @@ public AsyncApiDocument CloneProtype(AsyncApiDocument prototype)
{
var jsonView = prototype.Serialize(AsyncApiVersion.AsyncApi2_0, AsyncApiFormat.Json);

var reader = new AsyncApiStringReader();
var settings = new AsyncApiReaderSettings
{
Bindings = BindingsCollection.All,
};

var cloned = reader.Read(jsonView, out var diagnostic);
var reader = new AsyncApiStringReader(settings);

if (prototype.Components is not null)
{
cloned.Components.ChannelBindings = prototype.Components.ChannelBindings;
cloned.Components.MessageBindings = prototype.Components.MessageBindings;
cloned.Components.OperationBindings = prototype.Components.OperationBindings;
cloned.Components.ServerBindings = prototype.Components.ServerBindings;
}
var cloned = reader.Read(jsonView, out var diagnostic);

if (diagnostic is not null)
{
foreach (var item in diagnostic.Errors)
{
var ignore =
!item.Message.Contains("The field 'channels' in 'document' object is REQUIRED") &&
!(item.Message.Contains("Binding") && item.Message.Contains("is not found"));
var ignore = !item.Message.Contains("The field 'channels' in 'document' object is REQUIRED");

if (ignore)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public void GenerateDocument_GeneratesDocumentWithKafkaOperationBinding()
publish.Bindings.Reference.Reference.ShouldBe("#/components/operationBindings/sample_kaffka");

document.AssertByMessage(publish, "anyTenantCreated");

document.Components.OperationBindings.ShouldContainKey("sample_kaffka");
var bindMap = document.Components.OperationBindings["sample_kaffka"];
var operationBinding = bindMap["kafka"];
var kafkaOperationBinding = operationBinding.ShouldBeOfType<KafkaOperationBinding>();

kafkaOperationBinding.ClientId.ShouldNotBeNull();
kafkaOperationBinding.ClientId.Type.ShouldBe(LEGO.AsyncAPI.Models.SchemaType.Integer);
}

[AsyncApi]
Expand Down

0 comments on commit 66240f8

Please sign in to comment.