Skip to content

Commit 87812a2

Browse files
authored
Alex/refactorallofthethings (#34)
Co-authored-by: Michael Friis <[email protected]> <3 Co-authored-by: boiled-water-tsar <[email protected]> <3
1 parent 272b5b4 commit 87812a2

File tree

267 files changed

+13155
-3747
lines changed

Some content is hidden

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

267 files changed

+13155
-3747
lines changed

AsyncAPI.sln

-30
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.Tests", "test
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI", "src\LEGO.AsyncAPI\LEGO.AsyncAPI.csproj", "{D4559946-300D-4C6F-B92B-4376414D19C9}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.E2E.Tests", "test\LEGO.AsyncAPI.E2E.Tests\LEGO.AsyncAPI.E2E.Tests.csproj", "{85E0F568-3B0C-4253-A03B-83578865A788}"
11-
EndProject
1210
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.Readers", "src\LEGO.AsyncAPI.Readers\LEGO.AsyncAPI.Readers.csproj", "{7D9C6FBA-4B6F-48A0-B3F5-E7357021F8F9}"
1311
EndProject
14-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.Readers.YamlExample", "examples\LEGO.AsyncAPI.Readers.YamlExample\LEGO.AsyncAPI.Readers.YamlExample.csproj", "{D6314FDA-A897-4CEF-8EB1-DC46510BEB7C}"
15-
EndProject
16-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.Readers.JsonExample", "examples\LEGO.AsyncAPI.Readers.JsonExample\LEGO.AsyncAPI.Readers.JsonExample.csproj", "{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}"
17-
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LEGO.AsyncAPI.Writers", "src\LEGO.AsyncAPI.Writers\LEGO.AsyncAPI.Writers.csproj", "{3CC2CCB8-BDF8-4C1F-AF59-851EC5B5968C}"
19-
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LEGO.AsyncAPI.Writers.Example", "examples\LEGO.AsyncAPI.Writers.Example\LEGO.AsyncAPI.Writers.Example.csproj", "{09C8FC87-D785-41C2-84B1-14B2F40099D7}"
21-
EndProject
2212
Global
2313
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2414
Debug|Any CPU = Debug|Any CPU
@@ -33,30 +23,10 @@ Global
3323
{D4559946-300D-4C6F-B92B-4376414D19C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
3424
{D4559946-300D-4C6F-B92B-4376414D19C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
3525
{D4559946-300D-4C6F-B92B-4376414D19C9}.Release|Any CPU.Build.0 = Release|Any CPU
36-
{85E0F568-3B0C-4253-A03B-83578865A788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37-
{85E0F568-3B0C-4253-A03B-83578865A788}.Debug|Any CPU.Build.0 = Debug|Any CPU
38-
{85E0F568-3B0C-4253-A03B-83578865A788}.Release|Any CPU.ActiveCfg = Release|Any CPU
39-
{85E0F568-3B0C-4253-A03B-83578865A788}.Release|Any CPU.Build.0 = Release|Any CPU
4026
{7D9C6FBA-4B6F-48A0-B3F5-E7357021F8F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4127
{7D9C6FBA-4B6F-48A0-B3F5-E7357021F8F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
4228
{7D9C6FBA-4B6F-48A0-B3F5-E7357021F8F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
4329
{7D9C6FBA-4B6F-48A0-B3F5-E7357021F8F9}.Release|Any CPU.Build.0 = Release|Any CPU
44-
{D6314FDA-A897-4CEF-8EB1-DC46510BEB7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{D6314FDA-A897-4CEF-8EB1-DC46510BEB7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{D6314FDA-A897-4CEF-8EB1-DC46510BEB7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{D6314FDA-A897-4CEF-8EB1-DC46510BEB7C}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49-
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
50-
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
51-
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Release|Any CPU.Build.0 = Release|Any CPU
52-
{3CC2CCB8-BDF8-4C1F-AF59-851EC5B5968C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53-
{3CC2CCB8-BDF8-4C1F-AF59-851EC5B5968C}.Debug|Any CPU.Build.0 = Debug|Any CPU
54-
{3CC2CCB8-BDF8-4C1F-AF59-851EC5B5968C}.Release|Any CPU.ActiveCfg = Release|Any CPU
55-
{3CC2CCB8-BDF8-4C1F-AF59-851EC5B5968C}.Release|Any CPU.Build.0 = Release|Any CPU
56-
{09C8FC87-D785-41C2-84B1-14B2F40099D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57-
{09C8FC87-D785-41C2-84B1-14B2F40099D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
58-
{09C8FC87-D785-41C2-84B1-14B2F40099D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
59-
{09C8FC87-D785-41C2-84B1-14B2F40099D7}.Release|Any CPU.Build.0 = Release|Any CPU
6030
EndGlobalSection
6131
GlobalSection(SolutionProperties) = preSolution
6232
HideSolutionNode = FALSE

examples/LEGO.AsyncAPI.Readers.JsonExample/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static async Task Main()
1414

1515
var asyncApiDocument = new AsyncApiStringReader().Read(await new StreamReader(stream).ReadToEndAsync(), out var diagnostic);
1616

17-
if (diagnostic.HasError)
17+
if (diagnostic.Errors.Any())
1818
{
1919
Console.WriteLine($"Error during spec parsing: {diagnostic.Errors.First()}");
2020
}

examples/LEGO.AsyncAPI.Writers.Example/LEGO.AsyncAPI.Writers.Example.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
<ItemGroup>
2424
<ProjectReference Include="..\..\src\LEGO.AsyncAPI.Readers\LEGO.AsyncAPI.Readers.csproj" />
25-
<ProjectReference Include="..\..\src\LEGO.AsyncAPI.Writers\LEGO.AsyncAPI.Writers.csproj" />
2625
</ItemGroup>
2726

2827
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) The LEGO Group. All rights reserved.
2+
3+
namespace LEGO.AsyncAPI.Readers
4+
{
5+
using LEGO.AsyncAPI.Extensions;
6+
using LEGO.AsyncAPI.Models;
7+
using LEGO.AsyncAPI.Readers.ParseNodes;
8+
9+
internal static partial class AsyncApiDeserializer
10+
{
11+
private static readonly FixedFieldMap<AsyncApiChannel> channelFixedFields = new()
12+
{
13+
{ "description", (a, n) => { a.Description = n.GetScalarValue(); } },
14+
{ "servers", (a, n) => { a.Servers = n.CreateSimpleList(s => s.GetScalarValue()); } },
15+
{ "subscribe", (a, n) => { a.Subscribe = LoadOperation(n); } },
16+
{ "publish", (a, n) => { a.Publish = LoadOperation(n); } },
17+
{ "parameters", (a, n) => { a.Parameters = n.CreateMapWithReference(ReferenceType.Parameter, LoadParameter); } },
18+
{ "bindings", (a, n) => { ; } }, //TODO: Figure out bindings
19+
};
20+
21+
private static readonly PatternFieldMap<AsyncApiChannel> channelPatternFields =
22+
new()
23+
{
24+
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
25+
};
26+
27+
public static AsyncApiChannel LoadChannel(ParseNode node)
28+
{
29+
var mapNode = node.CheckMapNode("channel");
30+
31+
var pathItem = new AsyncApiChannel();
32+
33+
ParseMap(mapNode, pathItem, channelFixedFields, channelPatternFields);
34+
35+
return pathItem;
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) The LEGO Group. All rights reserved.
2+
3+
namespace LEGO.AsyncAPI.Readers
4+
{
5+
using LEGO.AsyncAPI.Extensions;
6+
using LEGO.AsyncAPI.Models;
7+
using LEGO.AsyncAPI.Readers.ParseNodes;
8+
9+
internal static partial class AsyncApiDeserializer
10+
{
11+
private static FixedFieldMap<AsyncApiComponents> componentsFixedFields = new()
12+
{
13+
{ "schemas", (a, n) => a.Schemas = n.CreateMapWithReference(ReferenceType.Schema, LoadSchema) },
14+
{ "servers", (a, n) => a.Servers = n.CreateMapWithReference(ReferenceType.Server, LoadServer) },
15+
{ "channels", (a, n) => a.Channels = n.CreateMapWithReference(ReferenceType.Channel, LoadChannel) },
16+
{ "messages", (a, n) => a.Messages = n.CreateMapWithReference(ReferenceType.Message, LoadMessage) },
17+
{ "securitySchemas", (a, n) => a.SecuritySchemes = n.CreateMapWithReference(ReferenceType.SecurityScheme, LoadSecurityScheme) },
18+
{ "parameters", (a, n) => a.Parameters = n.CreateMapWithReference(ReferenceType.Parameter, LoadParameter) },
19+
{ "correlationIds", (a, n) => a.CorrelationIds = n.CreateMapWithReference(ReferenceType.CorrelationId, LoadCorrelationId) },
20+
{ "operationTraits", (a, n) => a.OperationTraits = n.CreateMapWithReference(ReferenceType.OperationTrait, LoadOperationTrait) },
21+
{ "messageTraits", (a, n) => a.MessageTraits = n.CreateMapWithReference(ReferenceType.MessageTrait, LoadMessageTrait) },
22+
23+
//{"serverBindings", (a, n) => a.ServerBindings = n.CreateMapWithReference(ReferenceType.ServerBinding, LoadServerBinding)}, // TODO: Do something with bindings
24+
//{"channelBindings", (a, n) => a.ChannelBindings = n.CreateMapWithReference(ReferenceType.ChannelBinding, LoadChannelBinding)},
25+
//{"operationBindings", (a, n) => a.OperationBindings = n.CreateMapWithReference(ReferenceType.OperationBinding, LoadOperationBinding)},
26+
//{"messageBindings", (a, n) => a.MessageBindings = n.CreateMapWithReference(ReferenceType.MessageBinding, LoadMessageBinding)},
27+
};
28+
29+
30+
private static PatternFieldMap<AsyncApiComponents> componentsPatternFields =
31+
new()
32+
{
33+
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
34+
};
35+
36+
public static AsyncApiComponents LoadComponents(ParseNode node)
37+
{
38+
var mapNode = node.CheckMapNode("components");
39+
var components = new AsyncApiComponents();
40+
41+
ParseMap(mapNode, components, componentsFixedFields, componentsPatternFields);
42+
43+
return components;
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) The LEGO Group. All rights reserved.
2+
3+
namespace LEGO.AsyncAPI.Readers
4+
{
5+
using System;
6+
using LEGO.AsyncAPI.Extensions;
7+
using LEGO.AsyncAPI.Models;
8+
using LEGO.AsyncAPI.Readers.ParseNodes;
9+
10+
/// <summary>
11+
/// Class containing logic to deserialize AsyncApi document into
12+
/// runtime AsyncApi object model.
13+
/// </summary>
14+
internal static partial class AsyncApiDeserializer
15+
{
16+
private static FixedFieldMap<AsyncApiContact> contactFixedFields = new()
17+
{
18+
{ "name", (o, n) => { o.Name = n.GetScalarValue(); } },
19+
{ "email", (o, n) => { o.Email = n.GetScalarValue(); } },
20+
{ "url", (o, n) => { o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute); } },
21+
};
22+
23+
private static PatternFieldMap<AsyncApiContact> contactPatternFields = new()
24+
{
25+
{ s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n)) },
26+
};
27+
28+
public static AsyncApiContact LoadContact(ParseNode node)
29+
{
30+
var mapNode = node as MapNode;
31+
var contact = new AsyncApiContact();
32+
33+
ParseMap(mapNode, contact, contactFixedFields, contactPatternFields);
34+
35+
return contact;
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) The LEGO Group. All rights reserved.
2+
3+
namespace LEGO.AsyncAPI.Readers
4+
{
5+
using LEGO.AsyncAPI.Extensions;
6+
using LEGO.AsyncAPI.Models;
7+
using LEGO.AsyncAPI.Readers.ParseNodes;
8+
9+
/// <summary>
10+
/// Class containing logic to deserialize AsyncAPI document into
11+
/// runtime AsyncAPI object model.
12+
/// </summary>
13+
internal static partial class AsyncApiDeserializer
14+
{
15+
private static readonly FixedFieldMap<AsyncApiCorrelationId> correlationIdFixedFileds =
16+
new()
17+
{
18+
{ "description", (a, n) => { a.Description = n.GetScalarValue(); } },
19+
{ "location", (a, n) => { a.Location = n.GetScalarValue(); } },
20+
};
21+
22+
private static readonly PatternFieldMap<AsyncApiCorrelationId> correlationIdPatternFields =
23+
new()
24+
{
25+
{ s => s.StartsWith("x-"), (a, p, n) => a.AddExtension(p, LoadExtension(p, n)) },
26+
};
27+
28+
public static AsyncApiCorrelationId LoadCorrelationId(ParseNode node)
29+
{
30+
var mapNode = node.CheckMapNode("correlationId");
31+
32+
var correlationId = new AsyncApiCorrelationId();
33+
foreach (var property in mapNode)
34+
{
35+
property.ParseField(correlationId, correlationIdFixedFileds, correlationIdPatternFields);
36+
}
37+
38+
return correlationId;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)