Skip to content

Commit f88e615

Browse files
committed
fix openapi linting
Since openapi.json does not always need to be created after build, the command is separated from the csproj file into a github action task. Related to: aliencube#221
1 parent 9b0def2 commit f88e615

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

.github/workflows/azure-dev-build-only.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ jobs:
4949
run: |
5050
dotnet new tool-manifest
5151
dotnet tool install SwashBuckle.AspNetCore.Cli
52+
53+
- name: Install Spectral Cli
54+
shell: bash
55+
run: |
56+
curl -L https://raw.github.com/stoplightio/spectral/master/scripts/install.sh | sh
5257
5358
- name: Restore NuGet packages
5459
shell: bash
@@ -61,9 +66,11 @@ jobs:
6166
dotnet build
6267
6368
- name: OpenAPI linting
64-
uses: stoplightio/spectral-action@latest
65-
with:
66-
file_glob: './src/AzureOpenAIProxy.ApiApp/openapi.json'
69+
shell: bash
70+
run: |
71+
API_VERSION=$(grep -oP 'public const string Version = "\K[^"]+' ./src/AzureOpenAIProxy.ApiApp/Constants.cs)
72+
dotnet swagger tofile --output ./openapi.json ./src/AzureOpenAIProxy.ApiApp/bin/Debug/net8.0/AzureOpenAIProxy.ApiApp.dll $API_VERSION
73+
spectral lint openapi.json
6774
6875
- name: Run unit tests
6976
shell: bash

.github/workflows/azure-dev.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ jobs:
6363
run: |
6464
dotnet new tool-manifest
6565
dotnet tool install SwashBuckle.AspNetCore.Cli
66+
67+
- name: Install Spectral Cli
68+
shell: bash
69+
run: |
70+
curl -L https://raw.github.com/stoplightio/spectral/master/scripts/install.sh | sh
6671
6772
- name: Restore NuGet packages
6873
shell: bash
@@ -75,9 +80,11 @@ jobs:
7580
dotnet build
7681
7782
- name: OpenAPI linting
78-
uses: stoplightio/spectral-action@latest
79-
with:
80-
file_glob: './src/AzureOpenAIProxy.ApiApp/openapi.json'
83+
shell: bash
84+
run: |
85+
API_VERSION=$(grep -oP 'public const string Version = "\K[^"]+' ./src/AzureOpenAIProxy.ApiApp/Constants.cs)
86+
dotnet swagger tofile --output ./openapi.json ./src/AzureOpenAIProxy.ApiApp/bin/Debug/net8.0/AzureOpenAIProxy.ApiApp.dll $API_VERSION
87+
spectral lint openapi.json
8188
8289
- name: Test solution
8390
shell: bash

src/AzureOpenAIProxy.ApiApp/AzureOpenAIProxy.ApiApp.csproj

-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77

8-
<!-- This should be the same value as the API version in Constant.cs -->
9-
<ApiVersion>v1.0.0</ApiVersion>
10-
118
<AssemblyName>AzureOpenAIProxy.ApiApp</AssemblyName>
129
<RootNamespace>AzureOpenAIProxy.ApiApp</RootNamespace>
1310
</PropertyGroup>
@@ -24,8 +21,4 @@
2421
<ProjectReference Include="..\AzureOpenAIProxy.ServiceDefaults\AzureOpenAIProxy.ServiceDefaults.csproj" />
2522
</ItemGroup>
2623

27-
<Target Name="CreateSwaggerJson" AfterTargets="Build" Condition="$(Configuration)=='Debug'">
28-
<Exec Command="dotnet swagger tofile --output ./openapi.json $(OutputPath)$(AssemblyName).dll $(ApiVersion)" WorkingDirectory="$(ProjectDir)" />
29-
</Target>
30-
3124
</Project>

0 commit comments

Comments
 (0)