Skip to content

Commit

Permalink
Fix string usage and remove extra usings
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Nov 23, 2024
1 parent 5a0073a commit afc4411
Show file tree
Hide file tree
Showing 116 changed files with 147 additions and 308 deletions.
10 changes: 1 addition & 9 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,22 @@
[CA1200] Avoid using cref tags with a prefix
[CA1304] The behavior of 'string.ToUpper()' could vary based on the current user's locale settings
[CA1305] The behavior of 'int.ToString()' could vary based on the current user's locale settings
[CA1310] The behavior of 'string.StartsWith(string)' could vary based on the current user's locale settings
[CA1311] The behavior of 'string.StartsWith(string)' could vary based on the current user's locale settings
[CA1507] Use nameof in place of string literal
[CA1510] Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance
[CA1514] 'System.ReadOnlySpan<char>.Slice(int, int)' uses a redundant length calculation that can be removed
[CA1710] Rename to end in either 'Dictionary' or 'Collection'
[CA1716] rename parameter property so that it no longer conflicts with the reserved language keyword
[CA1720] Identifier 'xxx' contains type name
[CA1725] Overriden parameter name mismatch
[CA1834] Use 'StringBuilder.Append(char)' instead of 'StringBuilder.Append(string)' when the input is a constant unit string
[CA1845] Use span-based 'string.Concat' and 'AsSpan' instead of 'Substring'
[CA1847] Use 'string.Contains(char)' instead of 'string.Contains(string)' - needs polyfill
[CA1861] Prefer 'static readonly' fields over constant array arguments
[CA1862] Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison
[CA1865] Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' - needs polyfill
[CA1866] Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' - needs polyfill
[CA1870] Use a cached 'SearchValues' instance for improved searching performance
[CA2249] Use 'string.Contains' instead of 'string.IndexOf' to improve readability - needs polyfill
[CA2263] Prefer the generic overload 'System.Enum.GetValues<TEnum>()'
[SYSLIB0012] 'Assembly.CodeBase' is obsolete
-->
<NoWarn>$(NoWarn);IDE0005;IDE0008;IDE0017;IDE0021;IDE0022;IDE0025;IDE0027;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0056;IDE0057;IDE0060;IDE0061;IDE0090;IDE0130;IDE0160;IDE0200;IDE0270;IDE0290;IDE0330</NoWarn>
<NoWarn>$(NoWarn);CA1200;CA1304;CA1305;CA1310;CA1311;CA1507;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1834;CA1845;CA1847;CA1861;CA1862;CA1865;CA1866;CA1870;CA2249;CA2263;SYSLIB0012</NoWarn>
<NoWarn>$(NoWarn);CA1200;CA1304;CA1305;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1845;CA1861;CA1870;CA2249;CA2263;SYSLIB0012</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class OpenApiDocumentMiddleware : OwinMiddleware
public OpenApiDocumentMiddleware(OwinMiddleware next, string path, IEnumerable<Type> controllerTypes, SwaggerSettings<WebApiOpenApiDocumentGeneratorSettings> settings)
: base(next)
{
_path = path.StartsWith("/") ? path : '/' + path;
_path = path.StartsWith('/') ? path : '/' + path;
_controllerTypes = controllerTypes;
_settings = settings;
}
Expand Down
3 changes: 3 additions & 0 deletions src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<Compile Include="..\NSwag.AspNetCore\SwaggerSettings.cs" Link="SwaggerSettings.cs" />
<Compile Include="..\NSwag.AspNetCore\SwaggerUiSettings.cs" Link="SwaggerUiSettings.cs" />
<Compile Include="..\NSwag.AspNetCore\SwaggerUiSettingsBase.cs" Link="SwaggerUiSettingsBase.cs" />
<Compile Include="..\NSwag.Core\Polyfills.cs">
<Link>Polyfills.cs</Link>
</Compile>
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/NSwag.AspNetCore.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection;

namespace NSwag.AspNetCore.Launcher
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public OpenApiDocumentMiddleware(RequestDelegate nextDelegate, IServiceProvider
_nextDelegate = nextDelegate;

_documentName = documentName;
_path = path.StartsWith("/") ? path : '/' + path;
_path = path.StartsWith('/') ? path : '/' + path;

_apiDescriptionGroupCollectionProvider = serviceProvider.GetService<IApiDescriptionGroupCollectionProvider>() ??
throw new InvalidOperationException("API Explorer not registered in DI.");
Expand Down
6 changes: 6 additions & 0 deletions src/NSwag.AspNetCore/NSwag.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<ProjectReference Include="..\NSwag.Generation.AspNetCore\NSwag.Generation.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\NSwag.Core\Polyfills.cs">
<Link>Polyfills.cs</Link>
</Compile>
</ItemGroup>

<Target Name="PopulateNuspec">
<PropertyGroup>
<NuspecProperties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.CodeGeneration.OperationNameGenerators;
using NSwag.Generation.WebApi;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/ArrayParameterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
1 change: 0 additions & 1 deletion src/NSwag.CodeGeneration.CSharp.Tests/BinaryTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NSwag.CodeGeneration.CSharp.Models;
using System.Threading.Tasks;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.CodeGeneration.CSharp.Models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
6 changes: 1 addition & 5 deletions src/NSwag.CodeGeneration.CSharp.Tests/FileDownloadTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
5 changes: 1 addition & 4 deletions src/NSwag.CodeGeneration.CSharp.Tests/FileTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/FileUploadTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.CSharp.Tests/FormParameterTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.CSharp.Tests/HeadRequestTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
1 change: 0 additions & 1 deletion src/NSwag.CodeGeneration.CSharp.Tests/InheritanceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NSwag.CodeGeneration.CSharp;
using System.Threading.Tasks;
using Xunit;

namespace NSwag.CodeGeneration.TypeScript.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.CSharp.Tests/ParameterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
Expand Down
7 changes: 1 addition & 6 deletions src/NSwag.CodeGeneration.CSharp.Tests/PlainResponseTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NSwag.Generation.WebApi;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/PlainTextBodyTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/QueryParameterTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/ResponseTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.CSharp.Tests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.CodeGeneration.CSharp.Models;
using NSwag.Generation.WebApi;
Expand Down
3 changes: 0 additions & 3 deletions src/NSwag.CodeGeneration.CSharp.Tests/WrapResponsesTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public CSharpParameterModel(
}

/// <summary>Gets a value indicating whether the type is a Nullable&lt;&gt;.</summary>
public bool IsSystemNullable => Type.EndsWith("?");
public bool IsSystemNullable => Type.EndsWith("?", StringComparison.Ordinal);

/// <summary>Gets the type of the parameter when used in a controller interface where we can set default values before calling.</summary>
public string TypeInControllerInterface => HasDefault ? Type.EndsWith("?") ? Type.Substring(0, Type.Length - 1) : Type : Type;
public string TypeInControllerInterface => HasDefault ? Type.EndsWith("?", StringComparison.Ordinal) ? Type.Substring(0, Type.Length - 1) : Type : Type;

/// <summary>Gets a value indicating whether the parameter name is a valid CSharp identifier.</summary>
public bool IsValidIdentifier => Name.Equals(VariableName, StringComparison.OrdinalIgnoreCase);
Expand Down
6 changes: 1 addition & 5 deletions src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema.CodeGeneration.TypeScript;
using NJsonSchema.Generation;
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.TypeScript.Tests/AngularJSTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;
using NSwag.Generation.WebApi;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;

Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.TypeScript.Tests/AngularTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;
using NSwag.Generation.WebApi;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using NJsonSchema.Generation;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.TypeScript.Tests
{
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.TypeScript.Tests/AxiosTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;
using NSwag.Generation.WebApi;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;

Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.TypeScript.Tests/BinaryTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.TypeScript.Tests
{
Expand Down
4 changes: 1 addition & 3 deletions src/NSwag.CodeGeneration.TypeScript.Tests/FetchTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;
using NSwag.Generation.WebApi;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;

namespace NSwag.CodeGeneration.TypeScript.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.TypeScript.Tests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;
using NSwag.Generation.WebApi;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema.Generation;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using NJsonSchema;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;
using NSwag.Generation.WebApi;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Xunit;
using Xunit;

namespace NSwag.CodeGeneration.TypeScript.Tests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NJsonSchema;
using NSwag.Generation.WebApi;
using System.Collections.Generic;
using Xunit;
using NJsonSchema.Generation;
using NJsonSchema.NewtonsoftJson.Generation;

namespace NSwag.CodeGeneration.TypeScript.Tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NJsonSchema.CodeGeneration.TypeScript;
using NSwag.Generation.WebApi;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Xunit;
using NJsonSchema.NewtonsoftJson.Converters;
using NJsonSchema.Generation;
using NJsonSchema;
using NJsonSchema.NewtonsoftJson.Generation;

Expand Down
Loading

0 comments on commit afc4411

Please sign in to comment.