From 271d7f6408cc1ad746bebfe500f5f834b00e4585 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Tue, 17 Oct 2023 19:35:43 +0200 Subject: [PATCH] Update NJS preview --- src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.CodeGeneration.CSharp.csproj | 2 +- .../NSwag.CodeGeneration.Tests.csproj | 2 +- .../NSwag.CodeGeneration.TypeScript.csproj | 2 +- src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj | 2 +- .../OpenApiToTypeScriptClientCommand.cs | 5 +++-- .../Commands/Document/CreateDocumentCommand.cs | 4 ++-- .../Commands/Document/ExecuteDocumentCommand.cs | 7 ++++--- src/NSwag.Commands/Commands/InputOutputCommandBase.cs | 3 ++- .../Commands/OutputCommandExtensions.cs | 11 ++++++----- src/NSwag.Commands/NSwagCommandProcessor.cs | 3 ++- src/NSwag.Commands/NSwagDocumentBase.cs | 4 ++-- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core.Yaml/OpenApiYamlDocument.cs | 2 +- src/NSwag.Core/NSwag.Core.csproj | 2 +- src/NSwag.Core/OpenApiDocument.cs | 3 ++- src/NSwag.Generation/NSwag.Generation.csproj | 2 +- .../SwaggerGenerators/SwaggerInputViewModel.cs | 3 ++- 18 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index c0681bc82c..343cfadc29 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index d9fcc7b3ee..a9b8232e52 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -16,6 +16,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj index c62d772886..cb7d4c31ff 100644 --- a/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj +++ b/src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index cc72e77bef..b1b4749d50 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -16,6 +16,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 054195d788..77722761fa 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs b/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs index 79adab7b84..0368d784ae 100644 --- a/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs +++ b/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToTypeScriptClientCommand.cs @@ -7,6 +7,7 @@ //----------------------------------------------------------------------- using System; +using System.IO; using System.Threading.Tasks; using NConsole; using NJsonSchema.CodeGeneration.TypeScript; @@ -405,9 +406,9 @@ public override async Task RunAsync(CommandLineProcessor processor, ICon public async Task RunAsync() { var additionalCode = ExtensionCode ?? string.Empty; - if (DynamicApis.FileExists(additionalCode)) + if (File.Exists(additionalCode)) { - additionalCode = DynamicApis.FileReadAllText(additionalCode); + additionalCode = File.ReadAllText(additionalCode); } Settings.TypeScriptGeneratorSettings.ExtensionCode = additionalCode; diff --git a/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs b/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs index 9c55efca4b..1964501515 100644 --- a/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs +++ b/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs @@ -6,9 +6,9 @@ // Rico Suter, mail@rsuter.com //----------------------------------------------------------------------- +using System.IO; using System.Threading.Tasks; using NConsole; -using NJsonSchema.Infrastructure; using NSwag.Commands.CodeGeneration; #pragma warning disable 1591 @@ -20,7 +20,7 @@ public class CreateDocumentCommand : IConsoleCommand { public async Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { - if (!DynamicApis.FileExists("nswag.json")) + if (!File.Exists("nswag.json")) { await CreateDocumentAsync("nswag.json"); host.WriteMessage("nswag.json file created."); diff --git a/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs b/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs index e788af5317..0cdb9c344d 100644 --- a/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs +++ b/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs @@ -7,6 +7,7 @@ //----------------------------------------------------------------------- using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using NConsole; @@ -33,14 +34,14 @@ public async Task RunAsync(CommandLineProcessor processor, IConsoleHost } else { - var hasNSwagJson = DynamicApis.FileExists("nswag.json"); + var hasNSwagJson = File.Exists("nswag.json"); if (hasNSwagJson) { await ExecuteDocumentAsync(host, "nswag.json"); } - var currentDirectory = DynamicApis.DirectoryGetCurrentDirectory(); - var files = DynamicApis.DirectoryGetFiles(currentDirectory, "*.nswag"); + var currentDirectory = Directory.GetCurrentDirectory(); + var files = Directory.GetFiles(currentDirectory, "*.nswag"); if (files.Any()) { foreach (var file in files) diff --git a/src/NSwag.Commands/Commands/InputOutputCommandBase.cs b/src/NSwag.Commands/Commands/InputOutputCommandBase.cs index 3ffb551862..6358d5d386 100644 --- a/src/NSwag.Commands/Commands/InputOutputCommandBase.cs +++ b/src/NSwag.Commands/Commands/InputOutputCommandBase.cs @@ -7,6 +7,7 @@ //----------------------------------------------------------------------- using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using NConsole; @@ -81,7 +82,7 @@ protected async Task GetJsonSchemaAsync() return await JsonSchema.FromJsonAsync(input).ConfigureAwait(false); } - if (DynamicApis.FileExists(input)) + if (File.Exists(input)) { return await JsonSchema.FromFileAsync(input).ConfigureAwait(false); } diff --git a/src/NSwag.Commands/Commands/OutputCommandExtensions.cs b/src/NSwag.Commands/Commands/OutputCommandExtensions.cs index 25cd9ca645..cbf47acfb6 100644 --- a/src/NSwag.Commands/Commands/OutputCommandExtensions.cs +++ b/src/NSwag.Commands/Commands/OutputCommandExtensions.cs @@ -7,6 +7,7 @@ //----------------------------------------------------------------------- using System; +using System.IO; using System.Threading.Tasks; using NConsole; using NJsonSchema.Infrastructure; @@ -32,10 +33,10 @@ public static Task TryWriteFileOutputAsync(this IOutputCommand command, st { if (!string.IsNullOrEmpty(path)) { - var directory = DynamicApis.PathGetDirectoryName(path); - if (!string.IsNullOrEmpty(directory) && DynamicApis.DirectoryExists(directory) == false) + var directory = Path.GetDirectoryName(path); + if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory) == false) { - DynamicApis.DirectoryCreateDirectory(directory); + Directory.CreateDirectory(directory); } var data = generator(); @@ -44,9 +45,9 @@ public static Task TryWriteFileOutputAsync(this IOutputCommand command, st data = newLineBehavior == NewLineBehavior.Auto ? data.Replace("\n", Environment.NewLine) : newLineBehavior == NewLineBehavior.CRLF ? data.Replace("\n", "\r\n") : data; - if (!DynamicApis.FileExists(path) || DynamicApis.FileReadAllText(path) != data) + if (!File.Exists(path) || File.ReadAllText(path) != data) { - DynamicApis.FileWriteAllText(path, data); + File.WriteAllText(path, data); host?.WriteMessage("Code has been successfully written to file.\n"); } diff --git a/src/NSwag.Commands/NSwagCommandProcessor.cs b/src/NSwag.Commands/NSwagCommandProcessor.cs index dd31745b3e..f80ea2628d 100644 --- a/src/NSwag.Commands/NSwagCommandProcessor.cs +++ b/src/NSwag.Commands/NSwagCommandProcessor.cs @@ -8,6 +8,7 @@ using System; using System.Diagnostics; +using System.IO; using System.Reflection; using System.Threading.Tasks; using NConsole; @@ -88,7 +89,7 @@ private void WriteBinDirectory() entryAssembly = typeof(NSwagCommandProcessor).GetTypeInfo().Assembly; } - var binDirectory = DynamicApis.PathGetDirectoryName(new Uri(entryAssembly.CodeBase).LocalPath); + var binDirectory = Path.GetDirectoryName(new Uri(entryAssembly.CodeBase).LocalPath); _host.WriteMessage("NSwag bin directory: " + binDirectory + "\n"); } catch (Exception exception) diff --git a/src/NSwag.Commands/NSwagDocumentBase.cs b/src/NSwag.Commands/NSwagDocumentBase.cs index 4e60e2345c..5784ac9813 100644 --- a/src/NSwag.Commands/NSwagDocumentBase.cs +++ b/src/NSwag.Commands/NSwagDocumentBase.cs @@ -170,7 +170,7 @@ protected static async Task LoadAsync( bool applyTransformations) where TDocument : NSwagDocumentBase, new() { - var data = DynamicApis.FileReadAllText(filePath); + var data = File.ReadAllText(filePath); data = TransformLegacyDocument(data, out var requiredLegacyTransformations); if (requiredLegacyTransformations) @@ -236,7 +236,7 @@ public static TDocument FromJson(string filePath, string data) /// The task. public Task SaveAsync() { - DynamicApis.FileWriteAllText(Path, ToJsonWithRelativePaths()); + File.WriteAllText(Path, ToJsonWithRelativePaths()); _latestData = JsonConvert.SerializeObject(this, Formatting.Indented, GetSerializerSettings()); return Task.CompletedTask; } diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 794775afef..683c119101 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/NSwag.Core.Yaml/OpenApiYamlDocument.cs b/src/NSwag.Core.Yaml/OpenApiYamlDocument.cs index 3082acd6bb..5a1ee26947 100644 --- a/src/NSwag.Core.Yaml/OpenApiYamlDocument.cs +++ b/src/NSwag.Core.Yaml/OpenApiYamlDocument.cs @@ -94,7 +94,7 @@ public static string ToYaml(this OpenApiDocument document) /// The . public static async Task FromFileAsync(string filePath, CancellationToken cancellationToken = default) { - var data = DynamicApis.FileReadAllText(filePath); + var data = File.ReadAllText(filePath); return await FromYamlAsync(data, filePath, cancellationToken).ConfigureAwait(false); } diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 03a2d9afa8..99f848e7bb 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.Core/OpenApiDocument.cs b/src/NSwag.Core/OpenApiDocument.cs index 653f4848c8..b915a5c1ba 100644 --- a/src/NSwag.Core/OpenApiDocument.cs +++ b/src/NSwag.Core/OpenApiDocument.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; @@ -221,7 +222,7 @@ public static async Task FromJsonAsync(string data, string docu /// The . public static async Task FromFileAsync(string filePath, CancellationToken cancellationToken = default) { - var data = DynamicApis.FileReadAllText(filePath); + var data = File.ReadAllText(filePath); return await FromJsonAsync(data, filePath, cancellationToken).ConfigureAwait(false); } diff --git a/src/NSwag.Generation/NSwag.Generation.csproj b/src/NSwag.Generation/NSwag.Generation.csproj index 8dfd868ac5..e6852368a4 100644 --- a/src/NSwag.Generation/NSwag.Generation.csproj +++ b/src/NSwag.Generation/NSwag.Generation.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/NSwagStudio/ViewModels/SwaggerGenerators/SwaggerInputViewModel.cs b/src/NSwagStudio/ViewModels/SwaggerGenerators/SwaggerInputViewModel.cs index 714bf246aa..c7b3aef600 100644 --- a/src/NSwagStudio/ViewModels/SwaggerGenerators/SwaggerInputViewModel.cs +++ b/src/NSwagStudio/ViewModels/SwaggerGenerators/SwaggerInputViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows.Input; @@ -27,7 +28,7 @@ await RunTaskAsync(async () => { json = url.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase) ? - await DynamicApis.HttpGetAsync(url, CancellationToken.None) : DynamicApis.FileReadAllText(url); + await DynamicApis.HttpGetAsync(url, CancellationToken.None) : File.ReadAllText(url); if (json.StartsWith("{")) {