From 01efc3b8b8252a52459a7aef86729db00f080be7 Mon Sep 17 00:00:00 2001
From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com>
Date: Thu, 6 Mar 2025 21:03:29 +0000
Subject: [PATCH] Add nswag
---
.../RdtClient.Web/.config/dotnet-tools.json | 10 ++-
server/RdtClient.Web/Program.cs | 26 ++++++
server/RdtClient.Web/RdtClient.Web.csproj | 2 +
server/RdtClient.Web/nswag.json | 83 +++++++++++++++++++
4 files changed, 120 insertions(+), 1 deletion(-)
create mode 100644 server/RdtClient.Web/nswag.json
diff --git a/server/RdtClient.Web/.config/dotnet-tools.json b/server/RdtClient.Web/.config/dotnet-tools.json
index 22ec382..96e8a9b 100644
--- a/server/RdtClient.Web/.config/dotnet-tools.json
+++ b/server/RdtClient.Web/.config/dotnet-tools.json
@@ -6,7 +6,15 @@
"version": "3.1.3",
"commands": [
"dotnet-ef"
- ]
+ ],
+ "rollForward": false
+ },
+ "nswag.consolecore": {
+ "version": "14.2.0",
+ "commands": [
+ "nswag"
+ ],
+ "rollForward": false
}
}
}
\ No newline at end of file
diff --git a/server/RdtClient.Web/Program.cs b/server/RdtClient.Web/Program.cs
index d1d676a..d26cb5e 100644
--- a/server/RdtClient.Web/Program.cs
+++ b/server/RdtClient.Web/Program.cs
@@ -1,7 +1,9 @@
using System.Diagnostics;
+using System.Reflection;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Hosting.WindowsServices;
+using NSwag;
using RdtClient.Data.Data;
using RdtClient.Data.Models.Internal;
using RdtClient.Service;
@@ -25,6 +27,30 @@ var appSettings = new AppSettings();
builder.Configuration.Bind(appSettings);
builder.Services.AddSingleton(appSettings);
+// Add services for client generation
+builder.Services.AddOpenApiDocument(options => {
+ options.PostProcess = document =>
+ {
+ document.Info = new OpenApiInfo
+ {
+ Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(),
+ Title = "RdtClient API",
+ Description = "A web interface to manage your torrents on a Debrid provider.",
+ License = new OpenApiLicense
+ {
+ Name = "MIT",
+ Url = "https://github.com/rogerfar/rdt-client/blob/master/LICENSE"
+ },
+ Contact = new OpenApiContact()
+ {
+ Name = "Source Code",
+ Url = "https://github.com/rogerfar/rdt-client",
+ },
+
+ };
+ };
+});
+
// Configure URLs
if (appSettings.Port <= 0)
{
diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj
index 0c43cfc..9167601 100644
--- a/server/RdtClient.Web/RdtClient.Web.csproj
+++ b/server/RdtClient.Web/RdtClient.Web.csproj
@@ -8,6 +8,7 @@
enable
enable
latest
+ true
@@ -38,6 +39,7 @@
+
diff --git a/server/RdtClient.Web/nswag.json b/server/RdtClient.Web/nswag.json
new file mode 100644
index 0000000..98b275b
--- /dev/null
+++ b/server/RdtClient.Web/nswag.json
@@ -0,0 +1,83 @@
+{
+ "runtime": "Net90",
+ "defaultVariables": null,
+ "documentGenerator": {
+ "aspNetCoreToOpenApi": {
+ "project": "RdtClient.Web.csproj",
+ "documentName": "v1",
+ "msBuildProjectExtensionsPath": null,
+ "configuration": null,
+ "runtime": null,
+ "targetFramework": null,
+ "noBuild": false,
+ "msBuildOutputPath": null,
+ "verbose": true,
+ "workingDirectory": null,
+ "aspNetCoreEnvironment": null,
+ "output": "openapi.json",
+ "newLineBehavior": "Auto"
+ }
+ },
+ "codeGenerators": {
+ "openApiToTypeScriptClient": {
+ "className": "{controller}Client",
+ "moduleName": "",
+ "namespace": "",
+ "typeScriptVersion": 5.0,
+ "template": "Fetch",
+ "promiseType": "Promise",
+ "httpClass": "HttpClient",
+ "withCredentials": false,
+ "useSingletonProvider": false,
+ "injectionTokenType": "OpaqueToken",
+ "rxJsVersion": 6.0,
+ "dateTimeType": "Date",
+ "nullValue": "Undefined",
+ "generateClientClasses": true,
+ "generateClientInterfaces": false,
+ "generateOptionalParameters": false,
+ "exportTypes": true,
+ "wrapDtoExceptions": false,
+ "exceptionClass": "ApiException",
+ "clientBaseClass": null,
+ "wrapResponses": false,
+ "wrapResponseMethods": [],
+ "generateResponseClasses": true,
+ "responseClass": "SwaggerResponse",
+ "protectedMethods": [],
+ "configurationClass": null,
+ "useTransformOptionsMethod": false,
+ "useTransformResultMethod": false,
+ "generateDtoTypes": true,
+ "operationGenerationMode": "MultipleClientsFromOperationId",
+ "markOptionalProperties": true,
+ "generateCloneMethod": false,
+ "typeStyle": "Class",
+ "enumStyle": "Enum",
+ "useLeafType": false,
+ "classTypes": [],
+ "extendedClasses": [],
+ "extensionCode": null,
+ "generateDefaultValues": true,
+ "excludedTypeNames": [],
+ "excludedParameterNames": [],
+ "handleReferences": false,
+ "generateTypeCheckFunctions": false,
+ "generateConstructorInterface": true,
+ "convertConstructorInterfaceData": false,
+ "importRequiredTypes": true,
+ "useGetBaseUrlMethod": false,
+ "baseUrlTokenName": "API_BASE_URL",
+ "queryNullValue": "",
+ "useAbortSignal": false,
+ "inlineNamedDictionaries": false,
+ "inlineNamedAny": false,
+ "includeHttpContext": false,
+ "templateDirectory": null,
+ "serviceHost": null,
+ "serviceSchemes": null,
+ "output": "../../client/src/app/apiClient.ts",
+ "newLineBehavior": "Auto"
+ }
+ }
+}
\ No newline at end of file