Skip to content

Commit 02097a9

Browse files
Added writers project; fixed serialization of empty arrays (LEGO#17)
Added Writers package publishing; adjusted Models serialization
1 parent 042c44d commit 02097a9

File tree

59 files changed

+883
-639
lines changed

Some content is hidden

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

59 files changed

+883
-639
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ jobs:
1717
runs-on: ${{ matrix.os }}
1818
strategy:
1919
matrix:
20-
os: [ windows-latest, macos-latest ]
20+
os: [ windows-latest, macos-latest ]
2121
steps:
2222
- uses: actions/checkout@v2
2323
- name: Setup .NET
2424
uses: actions/setup-dotnet@v1
2525
with:
2626
dotnet-version: '6.0.x'
2727
include-prerelease: true
28+
- name: Add Nuget source Lego
29+
run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/lego/index.json"
2830
- name: Restore dependencies
29-
run: dotnet restore
31+
run: dotnet restore
3032
- name: Build
3133
run: dotnet build --no-restore
3234
- name: Test

.github/workflows/release-package.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ on:
55
paths:
66
- 'src/LEGO.AsyncAPI/**'
77
- 'src/LEGO.AsyncAPI.Readers/**'
8+
- 'src/LEGO.AsyncAPI.Writers/**'
89
- ".github/workflows/release-package.yml"
910
- '!**/*.md'
1011
workflow_dispatch:
1112

1213
jobs:
1314
release:
1415
runs-on: ubuntu-latest
15-
name: Publish a NuGet package
16+
name: Publish NuGet packages
17+
strategy:
18+
matrix:
19+
package-name: [ "LEGO.AsyncAPI", "LEGO.AsyncAPI.Readers", "LEGO.AsyncAPI.Writers"]
1620
steps:
1721
- name: Checkout repository
1822
uses: actions/checkout@v1
@@ -24,15 +28,9 @@ jobs:
2428
env:
2529
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
2630

27-
- name: Build LEGO.AsyncAPI project and pack NuGet package
28-
run: dotnet pack src/LEGO.AsyncAPI/LEGO.AsyncAPI.csproj -c Release -o out -p:PackageVersion=1.0.$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER
31+
- name: Build ${{ matrix.package-name }} project and pack NuGet package
32+
run: dotnet pack src/${{ matrix.package-name }}/${{ matrix.package-name }}.csproj -c Release -o out-${{ matrix.package-name }} -p:PackageVersion=0.1.$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER-prerelease
2933

3034
- name: Push generated package to GitHub Packages registry
31-
run: dotnet nuget push out/*.nupkg --skip-duplicate -n --api-key ${{secrets.GITHUB_TOKEN}}
32-
33-
- name: Build LEGO.AsyncAPI.Readers project and pack NuGet package
34-
run: dotnet pack src/LEGO.AsyncAPI.Readers/LEGO.AsyncAPI.Readers.csproj -c Release -o out_readers -p:PackageVersion=1.0.$GITHUB_RUN_ID.$GITHUB_RUN_NUMBER
35-
36-
- name: Push generated package to GitHub Packages registry
37-
run: dotnet nuget push out_readers/*.nupkg --skip-duplicate -n --api-key ${{secrets.GITHUB_TOKEN}}
35+
run: dotnet nuget push out-${{ matrix.package-name }}/*.nupkg --skip-duplicate -n --api-key ${{secrets.GITHUB_TOKEN}}
3836

AsyncAPI.sln

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LEGO.AsyncAPI.Readers.YamlE
1515
EndProject
1616
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}"
1717
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
1822
Global
1923
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2024
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +49,14 @@ Global
4549
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
4650
{DACCA48F-6BA9-4552-B5A4-2D7ECAD328BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
4751
{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
4860
EndGlobalSection
4961
GlobalSection(SolutionProperties) = preSolution
5062
HideSolutionNode = FALSE

examples/LEGO.AsyncAPI.Readers.JsonExample/LEGO.AsyncAPI.Readers.JsonExample.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19+
<PackageReference Include="LEGO.AsyncAPI.Readers" Version="*-*" />
1920
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
2021
<PrivateAssets>all</PrivateAssets>
2122
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2223
</PackageReference>
2324
</ItemGroup>
2425

25-
<ItemGroup>
26-
<ProjectReference Include="..\..\src\LEGO.AsyncAPI.Readers\LEGO.AsyncAPI.Readers.csproj" />
27-
</ItemGroup>
28-
2926
</Project>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static async Task Main()
1212
var stream = typeof(Program).Assembly.GetManifestResourceStream(typeof(Program).Assembly
1313
.GetManifestResourceNames().First(x => x.EndsWith("CompleteKafkaSpec.json")));
1414

15-
var openApiDocument = new AsyncApiStringReader().Read(await new StreamReader(stream).ReadToEndAsync(), out var diagnostic);
15+
var asyncApiDocument = new AsyncApiStringReader().Read(await new StreamReader(stream).ReadToEndAsync(), out var diagnostic);
1616

1717
if (diagnostic.HasError)
1818
{
@@ -21,8 +21,8 @@ static async Task Main()
2121
else
2222
{
2323
Console.WriteLine("Kafka Starlight JSON spec successfully parsed into AsyncApiDocument object");
24-
Console.WriteLine($"Api version: {openApiDocument.Asyncapi}");
25-
Console.WriteLine($"Number of channels: {openApiDocument.Channels.Count}");
24+
Console.WriteLine($"Api version: {asyncApiDocument.Asyncapi}");
25+
Console.WriteLine($"Number of channels: {asyncApiDocument.Channels.Count}");
2626
}
2727
}
2828
}

examples/LEGO.AsyncAPI.Readers.YamlExample/LEGO.AsyncAPI.Readers.YamlExample.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="LEGO.AsyncAPI.Readers" Version="0.1.2008926433.35-prerelease" />
1112
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
1213
<PrivateAssets>all</PrivateAssets>
1314
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1415
</PackageReference>
1516
</ItemGroup>
1617

17-
<ItemGroup>
18-
<ProjectReference Include="..\..\src\LEGO.AsyncAPI.Readers\LEGO.AsyncAPI.Readers.csproj" />
19-
</ItemGroup>
20-
2118
</Project>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static async Task Main()
2020

2121
var streetlightKafkaSpec = await new StreamReader(stream, Encoding.UTF8).ReadToEndAsync();
2222

23-
var openApiDocument = new AsyncApiStringReader().Read(streetlightKafkaSpec, out var diagnostic);
23+
var asyncApiDocument = new AsyncApiStringReader().Read(streetlightKafkaSpec, out var diagnostic);
2424

2525
if (diagnostic.HasError)
2626
{
@@ -29,8 +29,8 @@ static async Task Main()
2929
else
3030
{
3131
Console.WriteLine("Kafka Starlight YAML spec successfully parsed into AsyncApiDocument object");
32-
Console.WriteLine($"Api version: {openApiDocument.Asyncapi}");
33-
Console.WriteLine($"Number of channels: {openApiDocument.Channels.Count}");
32+
Console.WriteLine($"Api version: {asyncApiDocument.Asyncapi}");
33+
Console.WriteLine($"Number of channels: {asyncApiDocument.Channels.Count}");
3434
}
3535
}
3636
}
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
{
2+
"asyncapi": "2.3.0",
3+
"info": {
4+
"title": "Streetlights Kafka API",
5+
"version": "1.0.0",
6+
"description": "The Smartylighting Streetlights API allows you to remotely manage the city lights.\n",
7+
"license": {
8+
"name": "Apache 2.0",
9+
"url": "https://www.apache.org/licenses/LICENSE-2.0"
10+
}
11+
},
12+
"servers": {
13+
"test": {
14+
"url": "test.mykafkacluster.org:8092",
15+
"protocol": "kafka-secure",
16+
"description": "Test broker",
17+
"security": [
18+
{
19+
"saslScram": []
20+
}
21+
]
22+
}
23+
},
24+
"defaultContentType": "application/json",
25+
"channels": {
26+
"smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured": {
27+
"description": "The topic on which measured values may be produced and consumed.",
28+
"parameters": {
29+
"streetlightId": {
30+
"$ref": "#/components/parameters/streetlightId"
31+
}
32+
},
33+
"publish": {
34+
"summary": "Inform about environmental lighting conditions of a particular streetlight.",
35+
"operationId": "receiveLightMeasurement",
36+
"traits": [
37+
{
38+
"$ref": "#/components/operationTraits/kafka"
39+
}
40+
],
41+
"message": {
42+
"$ref": "#/components/messages/lightMeasured"
43+
}
44+
}
45+
},
46+
"smartylighting.streetlights.1.0.action.{streetlightId}.turn.on": {
47+
"parameters": {
48+
"streetlightId": {
49+
"$ref": "#/components/parameters/streetlightId"
50+
}
51+
},
52+
"subscribe": {
53+
"operationId": "turnOn",
54+
"traits": [
55+
{
56+
"$ref": "#/components/operationTraits/kafka"
57+
}
58+
],
59+
"message": {
60+
"$ref": "#/components/messages/turnOnOff"
61+
}
62+
}
63+
},
64+
"smartylighting.streetlights.1.0.action.{streetlightId}.turn.off": {
65+
"parameters": {
66+
"streetlightId": {
67+
"$ref": "#/components/parameters/streetlightId"
68+
}
69+
},
70+
"subscribe": {
71+
"operationId": "turnOff",
72+
"traits": [
73+
{
74+
"$ref": "#/components/operationTraits/kafka"
75+
}
76+
],
77+
"message": {
78+
"$ref": "#/components/messages/turnOnOff"
79+
}
80+
}
81+
},
82+
"smartylighting.streetlights.1.0.action.{streetlightId}.dim": {
83+
"parameters": {
84+
"streetlightId": {
85+
"$ref": "#/components/parameters/streetlightId"
86+
}
87+
},
88+
"subscribe": {
89+
"operationId": "dimLight",
90+
"traits": [
91+
{
92+
"$ref": "#/components/operationTraits/kafka"
93+
}
94+
],
95+
"message": {
96+
"$ref": "#/components/messages/dimLight"
97+
}
98+
}
99+
}
100+
},
101+
"components": {
102+
"messages": {
103+
"lightMeasured": {
104+
"name": "lightMeasured",
105+
"title": "Light measured",
106+
"summary": "Inform about environmental lighting conditions of a particular streetlight.",
107+
"contentType": "application/json",
108+
"traits": [
109+
{
110+
"$ref": "#/components/messageTraits/commonHeaders"
111+
}
112+
],
113+
"payload": {
114+
"$ref": "#/components/schemas/lightMeasuredPayload"
115+
}
116+
},
117+
"turnOnOff": {
118+
"name": "turnOnOff",
119+
"title": "Turn on/off",
120+
"summary": "Command a particular streetlight to turn the lights on or off.",
121+
"traits": [
122+
{
123+
"$ref": "#/components/messageTraits/commonHeaders"
124+
}
125+
],
126+
"payload": {
127+
"$ref": "#/components/schemas/turnOnOffPayload"
128+
}
129+
},
130+
"dimLight": {
131+
"name": "dimLight",
132+
"title": "Dim light",
133+
"summary": "Command a particular streetlight to dim the lights.",
134+
"traits": [
135+
{
136+
"$ref": "#/components/messageTraits/commonHeaders"
137+
}
138+
],
139+
"payload": {
140+
"$ref": "#/components/schemas/dimLightPayload"
141+
}
142+
}
143+
},
144+
"schemas": {
145+
"lightMeasuredPayload": {
146+
"type": "object",
147+
"properties": {
148+
"lumens": {
149+
"type": "integer",
150+
"minimum": "0",
151+
"description": "Light intensity measured in lumens."
152+
},
153+
"sentAt": {
154+
"$ref": "#/components/schemas/sentAt"
155+
}
156+
}
157+
},
158+
"turnOnOffPayload": {
159+
"type": "object",
160+
"properties": {
161+
"command": {
162+
"type": "string",
163+
"enum": [ "on", "off" ],
164+
"description": "Whether to turn on or off the light."
165+
},
166+
"sentAt": {
167+
"$ref": "#/components/schemas/sentAt"
168+
}
169+
}
170+
},
171+
"dimLightPayload": {
172+
"type": "object",
173+
"properties": {
174+
"percentage": {
175+
"type": "integer",
176+
"description": "Percentage to which the light should be dimmed to.",
177+
"minimum": "0",
178+
"maximum": "100"
179+
},
180+
"sentAt": {
181+
"$ref": "#/components/schemas/sentAt"
182+
}
183+
}
184+
},
185+
"sentAt": {
186+
"type": "string",
187+
"format": "date-time",
188+
"description": "Date and time when the message was sent."
189+
}
190+
},
191+
"securitySchemes": {
192+
"saslScram": {
193+
"type": "scramSha256",
194+
"description": "Provide your username and password for SASL/SCRAM authentication"
195+
}
196+
},
197+
"parameters": {
198+
"streetlightId": {
199+
"description": "The ID of the streetlight.",
200+
"schema": {
201+
"type": "string"
202+
}
203+
}
204+
},
205+
"messageTraits": {
206+
"commonHeaders": {
207+
"headers": {
208+
"type": "object",
209+
"properties": {
210+
"my-app-header": {
211+
"type": "integer",
212+
"minimum": "0",
213+
"maximum": "100"
214+
}
215+
}
216+
}
217+
}
218+
},
219+
"operationTraits": {
220+
"kafka": {
221+
"bindings": {
222+
"kafka": {
223+
"clientId": {
224+
"type": "string",
225+
"enum": [ "my-app-id" ]
226+
}
227+
}
228+
}
229+
}
230+
}
231+
}
232+
}

0 commit comments

Comments
 (0)