Skip to content

Commit

Permalink
Add Swagger UI to service frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 23, 2024
1 parent d9a4cfb commit 32b85a6
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 48 deletions.
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 32b85a6

Please sign in to comment.