-
Notifications
You must be signed in to change notification settings - Fork 18
Reading
The AsyncApiReader is a component in your .NET library that can be used to deserialize AsyncAPI specifications from either JSON or YAML formats. The deserialized AsyncAPI document can then be manipulated in memory as a C# object.
To use any of the AsyncApiReaders, you first need to create an instance.
There are 3 types of readers, which all have the same API
AsyncApiStringReader
AsyncApiStreamReader
AsyncApiTextReader
To use any of the AsyncApiReaders, you first need to create an instance.
``` csharp
var reader = new AsyncApiStringReader();
var doc = reader.Read(yaml, out var diagnostic);
You can override default reader settings by passing in an AsyncApiReaderSettings object.
or overriding settings
var settings = new AsyncApiReaderSettings();
var reader = new AsyncApiStringReader(settings);
The settings object holds a few different settings that can be applied.
You can use ReferenceResolutionSetting.DoNotResolveReferences
to enforce not resolving references during deserialization.
For more information see Reference Resolution
Extension parsers enable you to transform extensions, in any way you want. See example below.
Func<IAsyncApiAny, IAsyncApiExtension> isRequiredExtensionParser = (any) =>
{
if (any.AnyType == AnyType.Object && any is AsyncApiObject value)
{
var hasValue = (value["hasValue"] as AsyncApiBoolean).Value;
if (hasValue)
{
return new AsyncApiString(((AsyncApiString)value["myValue"]).Value);
}
}
return new AsyncApiString("No value provided");
};
var settings = new AsyncApiReaderSettings
{
ExtensionParsers = new Dictionary<string, Func<IAsyncApiAny, IAsyncApiExtension>>
{
{ "x-isrequired", isRequiredExtensionParser }
}
};