Skip to content

Commit a1b52a3

Browse files
authored
Merge branch 'vnext' into main
2 parents 883515c + 3355ac9 commit a1b52a3

File tree

75 files changed

+2197
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2197
-146
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,48 @@ var stream = await httpClient.GetStreamAsync("master/examples/streetlights-kafka
7878
var asyncApiDocument = new AsyncApiStreamReader().Read(stream, out var diagnostic);
7979
```
8080

81+
#### Reading External $ref
82+
83+
You can read externally referenced AsyncAPI documents by setting the `ReferenceResolution` property of the `AsyncApiReaderSettings` object to `ReferenceResolutionSetting.ResolveAllReferences` and providing an implementation for the `IAsyncApiExternalReferenceReader` interface. This interface contains a single method to which the built AsyncAPI.NET reader library will pass the location content contained in a `$ref` property (usually some form of path) and interface will return the content which is retrieved from wherever the `$ref` points to as a `string`. The AsyncAPI.NET reader will then automatically infer the `T` type of the content and recursively parse the external content into an AsyncAPI document as a child of the original document that contained the `$ref`. This means that you can have externally referenced documents that themselves contain external references.
84+
85+
This interface allows users to load the content of their external reference however and from whereever is required. A new instance of the implementor of `IAsyncApiExternalReferenceReader` should be registered with the `ExternalReferenceReader` property of the `AsyncApiReaderSettings` when creating the reader from which the `GetExternalResource` method will be called when resolving external references.
86+
87+
Below is a very simple example of implementation for `IAsyncApiExternalReferenceReader` that simply loads a file and returns it as a string found at the reference endpoint.
88+
```csharp
89+
using System.IO;
90+
91+
public class AsyncApiExternalFileSystemReader : IAsyncApiExternalReferenceReader
92+
{
93+
public string GetExternalResource(string reference)
94+
{
95+
return File.ReadAllText(reference);
96+
}
97+
}
98+
```
99+
100+
This can then be configured in the reader as follows:
101+
```csharp
102+
var settings = new AsyncApiReaderSettings
103+
{
104+
ReferenceResolution = ReferenceResolutionSetting.ResolveAllReferences,
105+
ExternalReferenceReader = new AsyncApiExternalFileSystemReader(),
106+
};
107+
var reader = new AsyncApiStringReader(settings);
108+
```
109+
110+
This would function for a AsyncAPI document with following reference to load the content of `message.yaml` as a `AsyncApiMessage` object inline with the document object.
111+
```yaml
112+
asyncapi: 2.3.0
113+
info:
114+
title: test
115+
version: 1.0.0
116+
channels:
117+
workspace:
118+
publish:
119+
message:
120+
$ref: "../../../message.yaml"
121+
```
122+
81123
### Bindings
82124
To add support for reading bindings, simply add the bindings you wish to support, to the `Bindings` collection of `AsyncApiReaderSettings`.
83125
There is a nifty helper to add different types of bindings, or like in the example `All` of them.

src/LEGO.AsyncAPI.Bindings/AMQP/AMQPOperationBinding.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace LEGO.AsyncAPI.Bindings.AMQP
55
using System;
66
using System.Collections.Generic;
77
using LEGO.AsyncAPI.Models;
8-
using LEGO.AsyncAPI.Readers;
98
using LEGO.AsyncAPI.Readers.ParseNodes;
109
using LEGO.AsyncAPI.Writers;
1110

src/LEGO.AsyncAPI.Bindings/BindingsCollection.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static TCollection Add<TCollection, TItem>(
4545
return destination;
4646
}
4747

48-
public static IEnumerable<IBindingParser<IBinding>> All => new List<IBindingParser<IBinding>>
48+
public static ICollection<IBindingParser<IBinding>> All => new List<IBindingParser<IBinding>>
4949
{
5050
Pulsar,
5151
Kafka,
@@ -57,51 +57,51 @@ public static TCollection Add<TCollection, TItem>(
5757
MQTT,
5858
};
5959

60-
public static IEnumerable<IBindingParser<IBinding>> Http => new List<IBindingParser<IBinding>>
60+
public static ICollection<IBindingParser<IBinding>> Http => new List<IBindingParser<IBinding>>
6161
{
6262
new HttpOperationBinding(),
6363
new HttpMessageBinding(),
6464
};
6565

66-
public static IEnumerable<IBindingParser<IBinding>> Websockets => new List<IBindingParser<IBinding>>
66+
public static ICollection<IBindingParser<IBinding>> Websockets => new List<IBindingParser<IBinding>>
6767
{
6868
new WebSocketsChannelBinding(),
6969
};
7070

71-
public static IEnumerable<IBindingParser<IBinding>> Kafka => new List<IBindingParser<IBinding>>
71+
public static ICollection<IBindingParser<IBinding>> Kafka => new List<IBindingParser<IBinding>>
7272
{
7373
new KafkaServerBinding(),
7474
new KafkaChannelBinding(),
7575
new KafkaOperationBinding(),
7676
new KafkaMessageBinding(),
7777
};
7878

79-
public static IEnumerable<IBindingParser<IBinding>> Pulsar => new List<IBindingParser<IBinding>>
79+
public static ICollection<IBindingParser<IBinding>> Pulsar => new List<IBindingParser<IBinding>>
8080
{
8181
new PulsarServerBinding(),
8282
new PulsarChannelBinding(),
8383
};
8484

85-
public static IEnumerable<IBindingParser<IBinding>> Sqs => new List<IBindingParser<IBinding>>
85+
public static ICollection<IBindingParser<IBinding>> Sqs => new List<IBindingParser<IBinding>>
8686
{
8787
new SqsChannelBinding(),
8888
new SqsOperationBinding(),
8989
};
9090

91-
public static IEnumerable<IBindingParser<IBinding>> Sns => new List<IBindingParser<IBinding>>
91+
public static ICollection<IBindingParser<IBinding>> Sns => new List<IBindingParser<IBinding>>
9292
{
9393
new SnsChannelBinding(),
9494
new SnsOperationBinding(),
9595
};
9696

97-
public static IEnumerable<IBindingParser<IBinding>> AMQP => new List<IBindingParser<IBinding>>
97+
public static ICollection<IBindingParser<IBinding>> AMQP => new List<IBindingParser<IBinding>>
9898
{
9999
new AMQPChannelBinding(),
100100
new AMQPOperationBinding(),
101101
new AMQPMessageBinding(),
102102
};
103103

104-
public static IEnumerable<IBindingParser<IBinding>> MQTT => new List<IBindingParser<IBinding>>
104+
public static ICollection<IBindingParser<IBinding>> MQTT => new List<IBindingParser<IBinding>>
105105
{
106106
new MQTTServerBinding(),
107107
new MQTTOperationBinding(),

src/LEGO.AsyncAPI.Bindings/Http/HttpMessageBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
4242
protected override FixedFieldMap<HttpMessageBinding> FixedFieldMap => new()
4343
{
4444
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
45-
{ "headers", (a, n) => { a.Headers = JsonSchemaDeserializer.LoadSchema(n); } },
45+
{ "headers", (a, n) => { a.Headers = AsyncApiSchemaDeserializer.LoadSchema(n); } },
4646
};
4747
}
4848
}

src/LEGO.AsyncAPI.Bindings/Http/HttpOperationBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
6363
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
6464
{ "type", (a, n) => { a.Type = n.GetScalarValue().GetEnumFromDisplayName<HttpOperationType>(); } },
6565
{ "method", (a, n) => { a.Method = n.GetScalarValue(); } },
66-
{ "query", (a, n) => { a.Query = JsonSchemaDeserializer.LoadSchema(n); } },
66+
{ "query", (a, n) => { a.Query = AsyncApiSchemaDeserializer.LoadSchema(n); } },
6767
};
6868

6969
public override string BindingKey => "http";

src/LEGO.AsyncAPI.Bindings/Kafka/KafkaMessageBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
6767
protected override FixedFieldMap<KafkaMessageBinding> FixedFieldMap => new()
6868
{
6969
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
70-
{ "key", (a, n) => { a.Key = JsonSchemaDeserializer.LoadSchema(n); } },
70+
{ "key", (a, n) => { a.Key = AsyncApiSchemaDeserializer.LoadSchema(n); } },
7171
{ "schemaIdLocation", (a, n) => { a.SchemaIdLocation = n.GetScalarValue(); } },
7272
{ "schemaIdPayloadEncoding", (a, n) => { a.SchemaIdPayloadEncoding = n.GetScalarValue(); } },
7373
{ "schemaLookupStrategy", (a, n) => { a.SchemaLookupStrategy = n.GetScalarValue(); } },

src/LEGO.AsyncAPI.Bindings/Kafka/KafkaOperationBinding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public class KafkaOperationBinding : OperationBinding<KafkaOperationBinding>
2828
protected override FixedFieldMap<KafkaOperationBinding> FixedFieldMap => new()
2929
{
3030
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
31-
{ "groupId", (a, n) => { a.GroupId = JsonSchemaDeserializer.LoadSchema(n); } },
32-
{ "clientId", (a, n) => { a.ClientId = JsonSchemaDeserializer.LoadSchema(n); } },
31+
{ "groupId", (a, n) => { a.GroupId = AsyncApiSchemaDeserializer.LoadSchema(n); } },
32+
{ "clientId", (a, n) => { a.ClientId = AsyncApiSchemaDeserializer.LoadSchema(n); } },
3333
};
3434

3535
/// <summary>

src/LEGO.AsyncAPI.Bindings/MQTT/LastWill.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace LEGO.AsyncAPI.Bindings.MQTT
44
{
5+
using System;
56
using LEGO.AsyncAPI.Models.Interfaces;
67
using LEGO.AsyncAPI.Writers;
7-
using System;
88

99
public class LastWill : IAsyncApiElement
1010
{

src/LEGO.AsyncAPI.Bindings/MQTT/MQTTMessageBinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void SerializeProperties(IAsyncApiWriter writer)
5757
protected override FixedFieldMap<MQTTMessageBinding> FixedFieldMap => new()
5858
{
5959
{ "payloadFormatIndicator", (a, n) => { a.PayloadFormatIndicator = n.GetIntegerValueOrDefault(); } },
60-
{ "correlationData", (a, n) => { a.CorrelationData = JsonSchemaDeserializer.LoadSchema(n); } },
60+
{ "correlationData", (a, n) => { a.CorrelationData = AsyncApiSchemaDeserializer.LoadSchema(n); } },
6161
{ "contentType", (a, n) => { a.ContentType = n.GetScalarValue(); } },
6262
{ "responseTopic", (a, n) => { a.ResponseTopic = n.GetScalarValue(); } },
6363
};

src/LEGO.AsyncAPI.Bindings/MQTT/MQTTOperationBinding.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
namespace LEGO.AsyncAPI.Bindings.MQTT
44
{
55
using System;
6-
using System.Collections.Generic;
7-
using LEGO.AsyncAPI.Models;
8-
using LEGO.AsyncAPI.Readers;
96
using LEGO.AsyncAPI.Readers.ParseNodes;
107
using LEGO.AsyncAPI.Writers;
118

0 commit comments

Comments
 (0)