You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All readers will write warnings and errors to the diagnostics.
82
137
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
138
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.
139
+
### Reference Resolution
140
+
Internal references are resolved by default. This includes component and non-component references e.g `#/components/messages/MyMessage` and `#/servers/0`.
141
+
External references can be resolved by setting `ReferenceResolution` to `ResolveAllReferences`.
142
+
The default implementation will resolve anything prefixed with `file://`, `http://` & `https://`, however a custom implementation can be made, by inhereting from the `IStreamLoader` interface and setting the `ExternalReferenceLoader` in the `AsyncApiReaderSettings`.
143
+
External references are always force converted to Json during resolution. This means that both yaml and json is supported - but not other serialization languages.
86
144
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.
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
-
```
151
+
152
+
Reference resolution can be disabled by setting `ReferenceResolution` to `DoNotResolveReferences`.
122
153
123
154
### Bindings
124
155
To add support for reading bindings, simply add the bindings you wish to support, to the `Bindings` collection of `AsyncApiReaderSettings`.
@@ -127,7 +158,7 @@ There is a nifty helper to add different types of bindings, or like in the examp
127
158
```csharp
128
159
varsettings=newAsyncApiReaderSettings();
129
160
settings.Bindings=BindingsCollection.All;
130
-
var asyncApiDocument = new AsyncApiStringReader(settings).Read(stream, out var diagnostic);
0 commit comments