Skip to content

Commit

Permalink
Rework module to be generic for any documentation tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Dec 15, 2024
1 parent e38d83a commit afb96a2
Show file tree
Hide file tree
Showing 15 changed files with 2,236 additions and 60 deletions.
12 changes: 6 additions & 6 deletions GenHTTP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenHTTP.Adapters.AspNetCore
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenHTTP.Modules.I18n", "Modules\GenHTTP.Modules.I18n\GenHTTP.Modules.I18n.csproj", "{E17F6CF0-295D-408C-9664-FE18C6E83433}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenHTTP.Modules.Swagger", "Modules\Swagger\GenHTTP.Modules.Swagger.csproj", "{8B6D634E-D804-41C8-BEB3-9958E57164F6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenHTTP.Modules.ApiBrowsing", "Modules\ApiBrowsing\GenHTTP.Modules.ApiBrowsing.csproj", "{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -263,10 +263,10 @@ Global
{E17F6CF0-295D-408C-9664-FE18C6E83433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E17F6CF0-295D-408C-9664-FE18C6E83433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E17F6CF0-295D-408C-9664-FE18C6E83433}.Release|Any CPU.Build.0 = Release|Any CPU
{8B6D634E-D804-41C8-BEB3-9958E57164F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B6D634E-D804-41C8-BEB3-9958E57164F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B6D634E-D804-41C8-BEB3-9958E57164F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B6D634E-D804-41C8-BEB3-9958E57164F6}.Release|Any CPU.Build.0 = Release|Any CPU
{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -311,7 +311,7 @@ Global
{7CEE048E-FA6A-4D8C-B6A6-EEEA0B048C54} = {AFBFE61E-0C33-42F6-9370-9F5088EB8633}
{AD7904BC-27BE-4EB5-84BC-62FF32DCBB78} = {C3265C1A-E9A9-45FD-BD24-66DE9C7062F1}
{E17F6CF0-295D-408C-9664-FE18C6E83433} = {23B23225-275E-4F52-8B29-6F44C85B6ACE}
{8B6D634E-D804-41C8-BEB3-9958E57164F6} = {23B23225-275E-4F52-8B29-6F44C85B6ACE}
{CE7DE343-E16D-46A6-A7F3-DF0CD96617F7} = {23B23225-275E-4F52-8B29-6F44C85B6ACE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9C67B3AF-0BF6-4E21-8C39-3F74CFCF9632}
Expand Down
37 changes: 37 additions & 0 deletions Modules/ApiBrowsing/ApiBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using GenHTTP.Modules.ApiBrowsing.Common;
using GenHTTP.Modules.Layouting.Provider;

namespace GenHTTP.Modules.ApiBrowsing;

public static class ApiBrowser
{

#region Factories

public static BrowserHandlerBuilder SwaggerUI() => new("Swagger");

public static BrowserHandlerBuilder Redoc() => new("Redoc");

#endregion

#region Layout extensions

public static LayoutBuilder AddSwaggerUI(this LayoutBuilder layout, string segment = "swagger", string? url = null)
=> AddBrowser(layout, SwaggerUI(), segment, url);

public static LayoutBuilder AddRedoc(this LayoutBuilder layout, string segment = "redoc", string? url = null)
=> AddBrowser(layout, Redoc(), segment, url);

private static LayoutBuilder AddBrowser(this LayoutBuilder layout, BrowserHandlerBuilder builder, string segment, string? url)
{
if (url != null)
{
builder.Url(url);
}

return layout.Add(segment, builder);
}

#endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using GenHTTP.Modules.Pages;
using GenHTTP.Modules.Pages.Rendering;

namespace GenHTTP.Modules.Swagger.Handler;
namespace GenHTTP.Modules.ApiBrowsing.Common;

public sealed class SwaggerUIHandler : IHandler
public sealed class BrowserHandler: IHandler
{

#region Get-/Setters
Expand All @@ -23,12 +23,12 @@ public sealed class SwaggerUIHandler : IHandler

#region Initialization

public SwaggerUIHandler(string? url)
public BrowserHandler(string resourceRoot, string? url)
{
StaticResources = Resources.From(ResourceTree.FromAssembly("Resources.Static"))
StaticResources = Resources.From(ResourceTree.FromAssembly($"{resourceRoot}.Static"))
.Build();

Template = Renderer.From(Resource.FromAssembly("Index.html").Build());
Template = Renderer.From(Resource.FromAssembly($"{resourceRoot}.Index.html").Build());

Url = url ?? "../openapi.json";
}
Expand Down
25 changes: 25 additions & 0 deletions Modules/ApiBrowsing/Common/BrowserHandlerBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using GenHTTP.Api.Content;

namespace GenHTTP.Modules.ApiBrowsing.Common;

public class BrowserHandlerBuilder(string resourceRoot) : IHandlerBuilder<BrowserHandlerBuilder>
{
private readonly List<IConcernBuilder> _Concerns = [];

private string? _Url;

public BrowserHandlerBuilder Url(string url)
{
_Url = url;
return this;
}

public BrowserHandlerBuilder Add(IConcernBuilder concern)
{
_Concerns.Add(concern);
return this;
}

public IHandler Build() => Concerns.Chain(_Concerns, new BrowserHandler(resourceRoot, _Url));

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageProjectUrl>https://genhttp.org/</PackageProjectUrl>

<Description>Serves Swagger UI for debugging purposes.</Description>
<PackageTags>HTTP Webserver C# Module Swagger UI</PackageTags>
<Description>Serves API browsers such as Swagger UI.</Description>
<PackageTags>HTTP Webserver C# Module Swagger UI API Browser Browsing</PackageTags>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand Down Expand Up @@ -56,12 +56,21 @@

<ItemGroup>
<None Remove="Resources\Static\swagger-ui.css" />
<EmbeddedResource Include="Resources\Static\swagger-ui.css" />
<None Remove="Resources\Static\swagger-ui-bundle.js" />
<EmbeddedResource Include="Resources\Static\swagger-ui-bundle.js" />
<None Remove="Resources\Static\swagger-ui-standalone-preset.js" />
<None Remove="Resources\Templates\Index.html" />
<EmbeddedResource Include="Resources\Templates\Index.html" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Redoc\Index.html" />
<EmbeddedResource Include="Redoc\Static\redoc-standalone.js" />
<EmbeddedResource Include="Redoc\Static\roboto.css" />
<EmbeddedResource Include="Swagger\Index.html" />
<EmbeddedResource Include="Swagger\Static\swagger-ui-bundle.js" />
<EmbeddedResource Include="Swagger\Static\swagger-ui.css" />
<None Remove="Redoc\Resources\Index.html" />
<None Remove="Redoc\Resources\Static\redoc.standalone.js" />
<None Remove="Redoc\Resources\Static\roboto.css" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions Modules/ApiBrowsing/Redoc/Index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Redoc</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="./static/roboto.css" rel="stylesheet">

<style>
body \{
margin: 0;
padding: 0;
\}
</style>
</head>
<body>
<redoc spec-url='{url}'></redoc>
<script src="./static/redoc-standalone.js"> </script>
</body>
</html>
1,826 changes: 1,826 additions & 0 deletions Modules/ApiBrowsing/Redoc/Static/redoc-standalone.js

Large diffs are not rendered by default.

Loading

0 comments on commit afb96a2

Please sign in to comment.