Skip to content

Commit

Permalink
Update NJS preview
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Oct 17, 2023
1 parent 66a733d commit 271d7f6
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview004" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="11.0.0-preview004" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview004" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.CodeGeneration.TypeScript" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.CodeGeneration.TypeScript" Version="11.0.0-preview004" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.CodeGeneration" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.CodeGeneration" Version="11.0.0-preview004" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System;
using System.IO;
using System.Threading.Tasks;
using NConsole;
using NJsonSchema.CodeGeneration.TypeScript;
Expand Down Expand Up @@ -405,9 +406,9 @@ public override async Task<object> RunAsync(CommandLineProcessor processor, ICon
public async Task<string> 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;
Expand Down
4 changes: 2 additions & 2 deletions src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// <author>Rico Suter, [email protected]</author>
//-----------------------------------------------------------------------

using System.IO;
using System.Threading.Tasks;
using NConsole;
using NJsonSchema.Infrastructure;
using NSwag.Commands.CodeGeneration;

#pragma warning disable 1591
Expand All @@ -20,7 +20,7 @@ public class CreateDocumentCommand : IConsoleCommand
{
public async Task<object> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NConsole;
Expand All @@ -33,14 +34,14 @@ public async Task<object> 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)
Expand Down
3 changes: 2 additions & 1 deletion src/NSwag.Commands/Commands/InputOutputCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NConsole;
Expand Down Expand Up @@ -81,7 +82,7 @@ protected async Task<JsonSchema> GetJsonSchemaAsync()
return await JsonSchema.FromJsonAsync(input).ConfigureAwait(false);
}

if (DynamicApis.FileExists(input))
if (File.Exists(input))
{
return await JsonSchema.FromFileAsync(input).ConfigureAwait(false);
}
Expand Down
11 changes: 6 additions & 5 deletions src/NSwag.Commands/Commands/OutputCommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System;
using System.IO;
using System.Threading.Tasks;
using NConsole;
using NJsonSchema.Infrastructure;
Expand All @@ -32,10 +33,10 @@ public static Task<bool> 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();
Expand All @@ -44,9 +45,9 @@ public static Task<bool> 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");
}
Expand Down
3 changes: 2 additions & 1 deletion src/NSwag.Commands/NSwagCommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using NConsole;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/NSwag.Commands/NSwagDocumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected static async Task<TDocument> LoadAsync<TDocument>(
bool applyTransformations)
where TDocument : NSwagDocumentBase, new()
{
var data = DynamicApis.FileReadAllText(filePath);
var data = File.ReadAllText(filePath);
data = TransformLegacyDocument(data, out var requiredLegacyTransformations);

if (requiredLegacyTransformations)
Expand Down Expand Up @@ -236,7 +236,7 @@ public static TDocument FromJson<TDocument>(string filePath, string data)
/// <returns>The task.</returns>
public Task SaveAsync()
{
DynamicApis.FileWriteAllText(Path, ToJsonWithRelativePaths());
File.WriteAllText(Path, ToJsonWithRelativePaths());
_latestData = JsonConvert.SerializeObject(this, Formatting.Indented, GetSerializerSettings());
return Task.CompletedTask;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.Yaml" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.Yaml" Version="11.0.0-preview004" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Core.Yaml/OpenApiYamlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static string ToYaml(this OpenApiDocument document)
/// <returns>The <see cref="OpenApiDocument" />.</returns>
public static async Task<OpenApiDocument> FromFileAsync(string filePath, CancellationToken cancellationToken = default)
{
var data = DynamicApis.FileReadAllText(filePath);
var data = File.ReadAllText(filePath);
return await FromYamlAsync(data, filePath, cancellationToken).ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Core/NSwag.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema" Version="11.0.0-preview004" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/NSwag.Core/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -221,7 +222,7 @@ public static async Task<OpenApiDocument> FromJsonAsync(string data, string docu
/// <returns>The <see cref="OpenApiDocument" />.</returns>
public static async Task<OpenApiDocument> FromFileAsync(string filePath, CancellationToken cancellationToken = default)
{
var data = DynamicApis.FileReadAllText(filePath);
var data = File.ReadAllText(filePath);
return await FromJsonAsync(data, filePath, cancellationToken).ConfigureAwait(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Generation/NSwag.Generation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview003" />
<PackageReference Include="NJsonSchema.NewtonsoftJson" Version="11.0.0-preview004" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
Expand Down Expand Up @@ -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("{"))
{
Expand Down

0 comments on commit 271d7f6

Please sign in to comment.