Skip to content

Commit

Permalink
Add Swagger UI to service frameworks (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat authored Dec 23, 2024
1 parent d9a4cfb commit bf6998c
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 48 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,59 @@ jobs:
- name: End scan
if: env.SONAR_TOKEN != null && env.SONAR_TOKEN != ''
run: dotnet sonarscanner end /d:sonar.token="$SONAR_TOKEN"
- name: Install templates
run: dotnet new install .
- name: Test webservice framework
run: |
mkdir -p /tmp/genhttp/webservice/
cd /tmp/genhttp/webservice/
dotnet new genhttp-webservice
cd webservice.Tests
dotnet test
cd /tmp/genhttp/webservice/
rm -rf ./webservice/bin/
rm -rf ./webservice/obj/
docker build -f Dockerfile.linux-x64 -t webservice .
- name: Test controller framework
run: |
mkdir -p /tmp/genhttp/controllers/
cd /tmp/genhttp/controllers/
dotnet new genhttp-webservice-controllers
cd controllers.Tests
dotnet test
cd /tmp/genhttp/controllers/
rm -rf ./controllers/bin/
rm -rf ./controllers/obj/
docker build -f Dockerfile.linux-x64 -t controllers .
- name: Test minimal framework
run: |
mkdir -p /tmp/genhttp/minimal/
cd /tmp/genhttp/minimal/
dotnet new genhttp-webservice-minimal
cd minimal.Tests
cd /tmp/genhttp/minimal/
rm -rf ./minimal/bin/
rm -rf ./minimal/obj/
docker build -f Dockerfile.linux-x64 -t minimal .
- name: Test static website
run: |
mkdir -p /tmp/genhttp/website/
cd /tmp/genhttp/website/
dotnet new genhttp-website-static
cd website.Tests
dotnet test
cd /tmp/genhttp/website/
rm -rf ./website/bin/
rm -rf ./website/obj/
docker build -f Dockerfile.linux-x64 -t website .
- name: Test websockets
run: |
mkdir -p /tmp/genhttp/websockets/
cd /tmp/genhttp/websockets/
dotnet new genhttp-websocket
cd websockets.Tests
dotnet test
cd /tmp/genhttp/websockets/
rm -rf ./websockets/bin/
rm -rf ./websockets/obj/
docker build -f Dockerfile.linux-x64 -t websocket .
2 changes: 1 addition & 1 deletion GenHTTP.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>

<PackageType>Template</PackageType>
<PackageVersion>9.3</PackageVersion>
<PackageVersion>9.4</PackageVersion>
<PackageId>GenHTTP.Templates</PackageId>

<Title>GenHTTP Templates</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.SinglePageApplications" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.SinglePageApplications" Version="9.4.0" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.Security" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.Controllers" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.Security" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.Controllers" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.ApiBrowsing" Version="9.4.0" />

</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions Templates/Webservice-Controllers/$safeprojectname$/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

using $safeprojectname$;

//
// GenHTTP Controller Framework Template
//
// URLs:
// http://localhost:8080/devices/
// http://localhost:8080/docs/
// http://localhost:8080/openapi.json
//
// Framework documentation:
// https://genhttp.org/documentation/content/frameworks/controllers/
//
// Method definitions:
// https://genhttp.org/documentation/content/concepts/definitions/
//
// Additional features:
// https://genhttp.org/documentation/content/
//

var project = Project.Setup();

return await Host.Create()
Expand Down
2 changes: 2 additions & 0 deletions Templates/Webservice-Controllers/$safeprojectname$/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GenHTTP.Modules.Security;
using GenHTTP.Modules.Controllers;
using GenHTTP.Modules.OpenApi;
using GenHTTP.Modules.ApiBrowsing;

using $safeprojectname$.Controllers;

Expand All @@ -17,6 +18,7 @@ public static IHandlerBuilder Setup()
return Layout.Create()
.AddController<DeviceController>("devices")
.AddOpenApi()
.AddSwaggerUI(segment: "docs")
.Add(CorsPolicy.Permissive());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.Security" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.Functional" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.Security" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.Functional" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.ApiBrowsing" Version="9.4.0" />

</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions Templates/Webservice-Minimal/$safeprojectname$/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

using $safeprojectname$;

//
// GenHTTP Functional Framework Template
//
// URLs:
// http://localhost:8080/devices/
// http://localhost:8080/docs/
// http://localhost:8080/openapi.json
//
// Framework documentation:
// https://genhttp.org/documentation/content/frameworks/functional/
//
// Method definitions:
// https://genhttp.org/documentation/content/concepts/definitions/
//
// Additional features:
// https://genhttp.org/documentation/content/
//

var project = Project.Setup();

return await Host.Create()
Expand Down
4 changes: 2 additions & 2 deletions Templates/Webservice-Minimal/$safeprojectname$/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GenHTTP.Modules.Security;
using GenHTTP.Modules.Functional;
using GenHTTP.Modules.OpenApi;
using GenHTTP.Modules.ApiBrowsing;

namespace $safeprojectname$;

Expand All @@ -14,20 +15,19 @@ public static class Project

public static IHandlerBuilder Setup()
{
// run this project and fetch a list of book records via http://localhost:8080/books/
var books = new List<Book>()
{
new Book(1, "Lord of the Rings")
};

// see https://genhttp.org/documentation/content/frameworks/functional/
var bookApi = Inline.Create()
.Get(() => books)
.Put((Book book) => books.Add(book));

return Layout.Create()
.Add("books", bookApi)
.AddOpenApi()
.AddSwaggerUI(segment: "docs")
.Add(CorsPolicy.Permissive());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
12 changes: 5 additions & 7 deletions Templates/Webservice/$safeprojectname$/$safeprojectname$.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.Security" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.Webservices" Version="9.3.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.Security" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.Webservices" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.OpenApi" Version="9.4.0" />
<PackageReference Include="GenHTTP.Modules.ApiBrowsing" Version="9.4.0" />

</ItemGroup>

Expand Down
19 changes: 17 additions & 2 deletions Templates/Webservice/$safeprojectname$/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@

using $safeprojectname$;

// run this project and access the api at http://localhost:8080/books/
// service specification at http://localhost:8080/openapi.json
//
// GenHTTP Webservice Framework Template
//
// URLs:
// http://localhost:8080/books/
// http://localhost:8080/docs/
// http://localhost:8080/openapi.json
//
// Framework documentation:
// https://genhttp.org/documentation/content/frameworks/webservices/
//
// Method definitions:
// https://genhttp.org/documentation/content/concepts/definitions/
//
// Additional features:
// https://genhttp.org/documentation/content/
//

var project = Project.Setup();

Expand Down
5 changes: 4 additions & 1 deletion Templates/Webservice/$safeprojectname$/Project.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using GenHTTP.Api.Content;
using System;
using GenHTTP.Api.Content;

using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Security;
using GenHTTP.Modules.Webservices;
using GenHTTP.Modules.OpenApi;
using GenHTTP.Modules.ApiBrowsing;

using $safeprojectname$.Services;

Expand All @@ -17,6 +19,7 @@ public static IHandlerBuilder Setup()
return Layout.Create()
.AddService<BookService>("books")
.AddOpenApi()
.AddSwaggerUI(segment: "docs")
.Add(CorsPolicy.Permissive());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.StaticWebsites" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.StaticWebsites" Version="9.4.0" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.4" />

<PackageReference Include="GenHTTP.Testing" Version="9.3.0" />
<PackageReference Include="GenHTTP.Testing" Version="9.4.0" />

<ProjectReference Include="..\$safeprojectname$\$safeprojectname$.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@

<ItemGroup>

<PackageReference Include="GenHTTP.Core" Version="9.3.0" />
<PackageReference Include="GenHTTP.Core" Version="9.4.0" />

<PackageReference Include="GenHTTP.Modules.Websockets" Version="9.3.0" />

<!-- see https://github.com/dotnet/sdk/issues/42651 -->
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-5f2m-466j-3848;https://github.com/advisories/GHSA-x5qj-9vmx-7g6g;https://github.com/advisories/GHSA-xhfc-gr8f-ffwc" />
<PackageReference Include="GenHTTP.Modules.Websockets" Version="9.4.0" />

</ItemGroup>

Expand Down

0 comments on commit bf6998c

Please sign in to comment.