Skip to content

Commit 2b98f81

Browse files
authored
feat!: full v3 support (#8)
BREAKING CHANGE: All models have changed to reflect v3.0
1 parent 1870fb2 commit 2b98f81

191 files changed

Lines changed: 7367 additions & 1315 deletions

File tree

Some content is hidden

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

Common.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Common Properties used by all assemblies -->
33
<PropertyGroup>
44
<LangVersion>10</LangVersion>
5-
<TargetFrameworks>netstandard2.0;net8</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.1;net8</TargetFrameworks>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Company>ByteBard</Company>
88
<PackageProjectUrl>https://github.com/ByteBardOrg/AsyncAPI.NET</PackageProjectUrl>

src/ByteBard.AsyncAPI.Readers/AsyncApiReaderSettings.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,5 @@ public ICollection<IBindingParser<IBinding>>
7171
/// External reference reader implementation provided by users for reading external resources.
7272
/// </summary>
7373
public IStreamLoader ExternalReferenceLoader { get; set; } = null;
74-
75-
/// <summary>
76-
/// URL where relative references should be resolved from if.
77-
/// </summary>
78-
public Uri BaseUrl { get; set; }
7974
}
8075
}

src/ByteBard.AsyncAPI.Readers/AsyncApiReferenceHostDocumentResolver.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/ByteBard.AsyncAPI.Readers/ByteBard.AsyncAPI.Readers.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
<PackageId>ByteBard.AsyncAPI.NET.Readers</PackageId>
77
<AssemblyName>ByteBard.AsyncAPI.Readers</AssemblyName>
88
<RootNamespace>ByteBard.AsyncAPI.Readers</RootNamespace>
9-
<TargetFrameworks>netstandard2.0;net8</TargetFrameworks>
109
</PropertyGroup>
1110

1211
<ItemGroup>
13-
<PackageReference Include="JsonPointer.Net" Version="5.0.2" />
12+
<PackageReference Include="JsonPointer.Net" Version="5.3.1" />
1413
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
1514
<PrivateAssets>all</PrivateAssets>
1615
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1716
</PackageReference>
18-
<PackageReference Include="System.Text.Json" Version="8.0.5" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
17+
<PackageReference Include="System.Text.Json" Version="9.0.1" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
1918
<PackageReference Include="YamlDotNet" Version="13.0.1" />
2019
</ItemGroup>
2120

src/ByteBard.AsyncAPI.Readers/V2/ExtensionHelpers.cs renamed to src/ByteBard.AsyncAPI.Readers/ExtensionHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public static IAsyncApiExtension LoadExtension(string name, ParseNode node)
3838
return node.CreateAny();
3939
}
4040
}
41-
}
41+
}

src/ByteBard.AsyncAPI.Readers/ParseNodes/ListNode.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ public override List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
5050
return this.nodeList.Select(n => map(new ValueNode(this.Context, n))).ToList();
5151
}
5252

53+
public override HashSet<T> CreateSimpleSet<T>(Func<ValueNode, T> map)
54+
{
55+
if (this.nodeList == null)
56+
{
57+
throw new AsyncApiReaderException(
58+
$"Expected list while parsing {typeof(T).Name}");
59+
}
60+
61+
return this.nodeList.Select(n => map(new ValueNode(this.Context, n))).ToHashSet();
62+
}
63+
5364
public IEnumerator<ParseNode> GetEnumerator()
5465
{
5566
return this.nodeList.Select(n => Create(this.Context, n)).ToList().GetEnumerator();

src/ByteBard.AsyncAPI.Readers/ParseNodes/MapNode.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,42 @@ public PropertyNode this[string key]
5050
}
5151
}
5252

53+
public override Dictionary<string, T> CreateMap<T>(Func<string, string> keySelector, Func<MapNode, string, T> map)
54+
{
55+
var jsonMap = this.node;
56+
if (jsonMap == null)
57+
{
58+
throw new AsyncApiReaderException($"Expected map while parsing {typeof(T).Name}", this.Context);
59+
}
60+
61+
var nodes = jsonMap.Select(
62+
n =>
63+
{
64+
var originalKey = n.Key;
65+
var newKey = keySelector(originalKey);
66+
T value;
67+
try
68+
{
69+
this.Context.StartObject(originalKey);
70+
value = n.Value is JsonObject
71+
? map(new MapNode(this.Context, n.Value), originalKey)
72+
: default(T);
73+
}
74+
finally
75+
{
76+
this.Context.EndObject();
77+
}
78+
79+
return new
80+
{
81+
key = newKey,
82+
value,
83+
};
84+
});
85+
86+
return nodes.ToDictionary(k => k.key, v => v.value);
87+
}
88+
5389
public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
5490
{
5591
var jsonMap = this.node;
@@ -207,14 +243,23 @@ public override AsyncApiAny CreateAny()
207243
return new AsyncApiAny(this.node);
208244
}
209245

210-
public void ParseFields<T>(ref T parentInstance, IDictionary<string, Action<T, ParseNode>> fixedFields, IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
246+
public void ParseFields<T>(T parentInstance, IDictionary<string, Action<T, ParseNode>> fixedFields, IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
211247
{
212248
foreach (var propertyNode in this)
213249
{
214250
propertyNode.ParseField(parentInstance, fixedFields, patternFields);
215251
}
216252
}
217253

254+
// Parse only patternfields on top.
255+
public void ParseFields<T>(T parentInstance, IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
256+
{
257+
foreach (var propertyNode in this)
258+
{
259+
propertyNode.ParseField(parentInstance, patternFields);
260+
}
261+
}
262+
218263
private string ToScalarValue(JsonNode node)
219264
{
220265
var scalarNode = node is JsonValue value ? value : throw new AsyncApiException($"Expected scalar value");

src/ByteBard.AsyncAPI.Readers/ParseNodes/ParseNode.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public virtual List<T> CreateList<T>(Func<MapNode, T> map)
4646
throw new AsyncApiReaderException("Cannot create list from this type of node.", this.Context);
4747
}
4848

49+
public virtual Dictionary<string, T> CreateMap<T>(Func<string, string> keySelector, Func<MapNode, string, T> map)
50+
{
51+
throw new AsyncApiReaderException("Cannot create map from this type of node.", this.Context);
52+
}
53+
4954
public virtual Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
5055
{
5156
throw new AsyncApiReaderException("Cannot create map from this type of node.", this.Context);
@@ -72,6 +77,11 @@ public virtual List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
7277
throw new AsyncApiReaderException("Cannot create simple list from this type of node.", this.Context);
7378
}
7479

80+
public virtual HashSet<T> CreateSimpleSet<T>(Func<ValueNode, T> map)
81+
{
82+
throw new AsyncApiReaderException("Cannot create simple list from this type of node.", this.Context);
83+
}
84+
7585
public virtual Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
7686
{
7787
throw new AsyncApiReaderException("Cannot create simple map from this type of node.", this.Context);

src/ByteBard.AsyncAPI.Readers/ParseNodes/PropertyNode.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ public PropertyNode(ParsingContext context, string name, JsonNode node)
2222

2323
public ParseNode Value { get; set; }
2424

25+
public void ParseField<T>(T parentInstance, IDictionary<Func<string, bool>, Action<T, string, ParseNode>> patternFields)
26+
{
27+
var map = patternFields.Where(p => p.Key(this.Name)).Select(p => p.Value).FirstOrDefault();
28+
if (map != null)
29+
{
30+
try
31+
{
32+
this.Context.StartObject(this.Name);
33+
map(parentInstance, this.Name, this.Value);
34+
}
35+
catch (AsyncApiReaderException ex)
36+
{
37+
this.Context.Diagnostic.Errors.Add(new AsyncApiError(ex));
38+
}
39+
catch (AsyncApiException ex)
40+
{
41+
ex.Pointer = this.Context.GetLocation();
42+
this.Context.Diagnostic.Errors.Add(new AsyncApiError(ex));
43+
}
44+
finally
45+
{
46+
this.Context.EndObject();
47+
}
48+
}
49+
}
50+
2551
public void ParseField<T>(
2652
T parentInstance,
2753
IDictionary<string, Action<T, ParseNode>> fixedFields,

src/ByteBard.AsyncAPI.Readers/ParseNodes/ValueNode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public override string GetScalarValue()
2727
{
2828
if (this.cachedScalarValue == null)
2929
{
30-
// TODO: Update this property to use the .ToString() or JsonReader.
3130
var scalarNode = this.node is JsonValue value ? value : throw new AsyncApiException($"Expected scalar value");
3231
this.cachedScalarValue = Convert.ToString(scalarNode.GetValue<object>(), this.Context.Settings.CultureInfo);
3332
}

0 commit comments

Comments
 (0)