From 32b85a674cb1f3e2a6c45c775a48814fe9765690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Mon, 23 Dec 2024 11:36:39 +0100 Subject: [PATCH] Add Swagger UI to service frameworks --- GenHTTP.Templates.csproj | 2 +- .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 7 ++----- .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 12 +++++------- .../$safeprojectname$/Program.cs | 18 ++++++++++++++++++ .../$safeprojectname$/Project.cs | 2 ++ .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 12 +++++------- .../$safeprojectname$/Program.cs | 18 ++++++++++++++++++ .../$safeprojectname$/Project.cs | 4 ++-- .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 12 +++++------- .../Webservice/$safeprojectname$/Program.cs | 19 +++++++++++++++++-- .../Webservice/$safeprojectname$/Project.cs | 5 ++++- .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 7 ++----- .../$safeprojectname$.Tests.csproj | 2 +- .../$safeprojectname$.csproj | 7 ++----- 19 files changed, 89 insertions(+), 48 deletions(-) diff --git a/GenHTTP.Templates.csproj b/GenHTTP.Templates.csproj index 9d14c2d..2fecf6a 100644 --- a/GenHTTP.Templates.csproj +++ b/GenHTTP.Templates.csproj @@ -3,7 +3,7 @@ Template - 9.3 + 9.4 GenHTTP.Templates GenHTTP Templates diff --git a/Templates/SinglePageApplication/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/SinglePageApplication/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index a040688..7cc9013 100644 --- a/Templates/SinglePageApplication/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/SinglePageApplication/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/SinglePageApplication/$safeprojectname$/$safeprojectname$.csproj b/Templates/SinglePageApplication/$safeprojectname$/$safeprojectname$.csproj index 5e10aca..972d7f9 100644 --- a/Templates/SinglePageApplication/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/SinglePageApplication/$safeprojectname$/$safeprojectname$.csproj @@ -19,12 +19,9 @@ - + - - - - + diff --git a/Templates/Webservice-Controllers/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/Webservice-Controllers/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index 29014e2..3486069 100644 --- a/Templates/Webservice-Controllers/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/Webservice-Controllers/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/Webservice-Controllers/$safeprojectname$/$safeprojectname$.csproj b/Templates/Webservice-Controllers/$safeprojectname$/$safeprojectname$.csproj index 9bf4df5..d0a6574 100644 --- a/Templates/Webservice-Controllers/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/Webservice-Controllers/$safeprojectname$/$safeprojectname$.csproj @@ -19,14 +19,12 @@ - + - - - - - - + + + + diff --git a/Templates/Webservice-Controllers/$safeprojectname$/Program.cs b/Templates/Webservice-Controllers/$safeprojectname$/Program.cs index 6aefc26..7a2ce03 100644 --- a/Templates/Webservice-Controllers/$safeprojectname$/Program.cs +++ b/Templates/Webservice-Controllers/$safeprojectname$/Program.cs @@ -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() diff --git a/Templates/Webservice-Controllers/$safeprojectname$/Project.cs b/Templates/Webservice-Controllers/$safeprojectname$/Project.cs index a89bfb9..3374082 100644 --- a/Templates/Webservice-Controllers/$safeprojectname$/Project.cs +++ b/Templates/Webservice-Controllers/$safeprojectname$/Project.cs @@ -4,6 +4,7 @@ using GenHTTP.Modules.Security; using GenHTTP.Modules.Controllers; using GenHTTP.Modules.OpenApi; +using GenHTTP.Modules.ApiBrowsing; using $safeprojectname$.Controllers; @@ -17,6 +18,7 @@ public static IHandlerBuilder Setup() return Layout.Create() .AddController("devices") .AddOpenApi() + .AddSwaggerUI(segment: "docs") .Add(CorsPolicy.Permissive()); } diff --git a/Templates/Webservice-Minimal/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/Webservice-Minimal/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index ac2ea70..65fa9cb 100644 --- a/Templates/Webservice-Minimal/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/Webservice-Minimal/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/Webservice-Minimal/$safeprojectname$/$safeprojectname$.csproj b/Templates/Webservice-Minimal/$safeprojectname$/$safeprojectname$.csproj index 91c453f..b40a7ea 100644 --- a/Templates/Webservice-Minimal/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/Webservice-Minimal/$safeprojectname$/$safeprojectname$.csproj @@ -19,14 +19,12 @@ - + - - - - - - + + + + diff --git a/Templates/Webservice-Minimal/$safeprojectname$/Program.cs b/Templates/Webservice-Minimal/$safeprojectname$/Program.cs index 6aefc26..78ae430 100644 --- a/Templates/Webservice-Minimal/$safeprojectname$/Program.cs +++ b/Templates/Webservice-Minimal/$safeprojectname$/Program.cs @@ -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() diff --git a/Templates/Webservice-Minimal/$safeprojectname$/Project.cs b/Templates/Webservice-Minimal/$safeprojectname$/Project.cs index bec704d..0b75e01 100644 --- a/Templates/Webservice-Minimal/$safeprojectname$/Project.cs +++ b/Templates/Webservice-Minimal/$safeprojectname$/Project.cs @@ -4,6 +4,7 @@ using GenHTTP.Modules.Security; using GenHTTP.Modules.Functional; using GenHTTP.Modules.OpenApi; +using GenHTTP.Modules.ApiBrowsing; namespace $safeprojectname$; @@ -14,13 +15,11 @@ 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() { 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)); @@ -28,6 +27,7 @@ public static IHandlerBuilder Setup() return Layout.Create() .Add("books", bookApi) .AddOpenApi() + .AddSwaggerUI(segment: "docs") .Add(CorsPolicy.Permissive()); } diff --git a/Templates/Webservice/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/Webservice/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index 29014e2..3486069 100644 --- a/Templates/Webservice/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/Webservice/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/Webservice/$safeprojectname$/$safeprojectname$.csproj b/Templates/Webservice/$safeprojectname$/$safeprojectname$.csproj index 78b7363..95e2fc6 100644 --- a/Templates/Webservice/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/Webservice/$safeprojectname$/$safeprojectname$.csproj @@ -19,14 +19,12 @@ - + - - - - - - + + + + diff --git a/Templates/Webservice/$safeprojectname$/Program.cs b/Templates/Webservice/$safeprojectname$/Program.cs index addb862..0376825 100644 --- a/Templates/Webservice/$safeprojectname$/Program.cs +++ b/Templates/Webservice/$safeprojectname$/Program.cs @@ -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(); diff --git a/Templates/Webservice/$safeprojectname$/Project.cs b/Templates/Webservice/$safeprojectname$/Project.cs index a239723..e2d0d21 100644 --- a/Templates/Webservice/$safeprojectname$/Project.cs +++ b/Templates/Webservice/$safeprojectname$/Project.cs @@ -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; @@ -17,6 +19,7 @@ public static IHandlerBuilder Setup() return Layout.Create() .AddService("books") .AddOpenApi() + .AddSwaggerUI(segment: "docs") .Add(CorsPolicy.Permissive()); } diff --git a/Templates/Website-Static/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/Website-Static/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index ac2ea70..65fa9cb 100644 --- a/Templates/Website-Static/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/Website-Static/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/Website-Static/$safeprojectname$/$safeprojectname$.csproj b/Templates/Website-Static/$safeprojectname$/$safeprojectname$.csproj index 63e7885..f2b2407 100644 --- a/Templates/Website-Static/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/Website-Static/$safeprojectname$/$safeprojectname$.csproj @@ -27,12 +27,9 @@ - + - - - - + diff --git a/Templates/Websocket/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj b/Templates/Websocket/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj index ac2ea70..65fa9cb 100644 --- a/Templates/Websocket/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj +++ b/Templates/Websocket/$safeprojectname$.Tests/$safeprojectname$.Tests.csproj @@ -19,7 +19,7 @@ - + diff --git a/Templates/Websocket/$safeprojectname$/$safeprojectname$.csproj b/Templates/Websocket/$safeprojectname$/$safeprojectname$.csproj index 7cd8121..53a6543 100644 --- a/Templates/Websocket/$safeprojectname$/$safeprojectname$.csproj +++ b/Templates/Websocket/$safeprojectname$/$safeprojectname$.csproj @@ -19,12 +19,9 @@ - + - - - - +