diff --git a/Directory.Build.props b/Directory.Build.props index 3745092c5d..d38c7488e8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -99,12 +99,10 @@ [CA1720] Identifier 'xxx' contains type name [CA1725] Overriden parameter name mismatch [CA1805] Member is explicitly initialized to its default value - [CA1822] Member does not access instance data and can be marked as static [CA1827] Count() is used where Any() could be used instead to improve performance [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 - [CA1852] Type can be sealed because it has no subtypes in its containing assembly and is not externally visible [CA1854] Prefer a 'TryGetValue' call over a Dictionary indexer access [CA1860] Prefer comparing 'Count' to 0 rather than using 'Any()' [CA1861] Prefer 'static readonly' fields over constant array arguments @@ -118,7 +116,7 @@ [SYSLIB0012] 'Assembly.CodeBase' is obsolete --> $(NoWarn);IDE0005;IDE0008;IDE0011;IDE0017;IDE0019;IDE0021;IDE0022;IDE0025;IDE0027;IDE0028;IDE0029;IDE0032;IDE0039;IDE0040;IDE0044;IDE0045;IDE0046;IDE0055;IDE0056;IDE0057;IDE0059;IDE0060;IDE0061;IDE0063;IDE0074;IDE0078;IDE0083;IDE0090;IDE0100;IDE0130;IDE0160;IDE0200;IDE0260;IDE0270;IDE0290;IDE0300;IDE0305;IDE0301;IDE0330;IDE1005 - $(NoWarn);CA1200;CA1304;CA1305;CA1310;CA1311;CA1507;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1805;CA1822;CA1827;CA1834;CA1845;CA1847;CA1852;CA1854;CA1860;CA1861;CA1862;CA1865;CA1866;CA1870;CA2249;CA2263;SYSLIB0012 + $(NoWarn);CA1200;CA1304;CA1305;CA1310;CA1311;CA1507;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1805;CA1827;CA1834;CA1845;CA1847;CA1854;CA1860;CA1861;CA1862;CA1865;CA1866;CA1870;CA2249;CA2263;SYSLIB0012 diff --git a/src/NSwag.AspNet.Owin/Middlewares/RedirectToIndexMiddleware.cs b/src/NSwag.AspNet.Owin/Middlewares/RedirectToIndexMiddleware.cs index 128ad39f69..7be088137a 100644 --- a/src/NSwag.AspNet.Owin/Middlewares/RedirectToIndexMiddleware.cs +++ b/src/NSwag.AspNet.Owin/Middlewares/RedirectToIndexMiddleware.cs @@ -12,7 +12,7 @@ namespace NSwag.AspNet.Owin.Middlewares { - internal class RedirectToIndexMiddleware : OwinMiddleware + internal sealed class RedirectToIndexMiddleware : OwinMiddleware { private readonly string _internalUiRoute; private readonly string _internalSwaggerRoute; diff --git a/src/NSwag.AspNet.Owin/Middlewares/SwaggerUiIndexMiddleware.cs b/src/NSwag.AspNet.Owin/Middlewares/SwaggerUiIndexMiddleware.cs index c4b8c9d2b5..c324b404cd 100644 --- a/src/NSwag.AspNet.Owin/Middlewares/SwaggerUiIndexMiddleware.cs +++ b/src/NSwag.AspNet.Owin/Middlewares/SwaggerUiIndexMiddleware.cs @@ -7,7 +7,7 @@ namespace NSwag.AspNet.Owin.Middlewares { - internal class SwaggerUiIndexMiddleware : OwinMiddleware + internal sealed class SwaggerUiIndexMiddleware : OwinMiddleware where T : OpenApiDocumentGeneratorSettings, new() { private readonly string _indexPath; diff --git a/src/NSwag.AspNet.WebApi/JsonExceptionFilterAttribute.cs b/src/NSwag.AspNet.WebApi/JsonExceptionFilterAttribute.cs index dee6534b24..142f493c9b 100644 --- a/src/NSwag.AspNet.WebApi/JsonExceptionFilterAttribute.cs +++ b/src/NSwag.AspNet.WebApi/JsonExceptionFilterAttribute.cs @@ -79,7 +79,7 @@ public override void OnActionExecuted(HttpActionExecutedContext context) } } - private int GetStatusCode(Exception exception, HttpActionExecutedContext context) + private static int GetStatusCode(Exception exception, HttpActionExecutedContext context) { if (context.ActionContext.ActionDescriptor is ReflectedHttpActionDescriptor actionDescriptor) { @@ -105,7 +105,7 @@ private int GetStatusCode(Exception exception, HttpActionExecutedContext context return 500; } - private JsonSerializerSettings CopySettings(JsonSerializerSettings settings) + private static JsonSerializerSettings CopySettings(JsonSerializerSettings settings) { var settingsCopy = new JsonSerializerSettings(); diff --git a/src/NSwag.AspNetCore.Launcher/Program.cs b/src/NSwag.AspNetCore.Launcher/Program.cs index e2c61b6b99..faefff2d55 100644 --- a/src/NSwag.AspNetCore.Launcher/Program.cs +++ b/src/NSwag.AspNetCore.Launcher/Program.cs @@ -5,7 +5,7 @@ namespace NSwag.AspNetCore.Launcher { - internal class Program + internal sealed class Program { // Used to load NSwag.Commands into a process running with the app's dependency context private const string EntryPointType = "NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint"; @@ -169,7 +169,7 @@ private static bool TryLoadReferencedAssemblies() return true; } - private class AssemblyLoadInfo + private sealed class AssemblyLoadInfo { public AssemblyLoadInfo(Version minimumRequiredVersion) { diff --git a/src/NSwag.AspNetCore/JsonExceptionFilterAttribute.cs b/src/NSwag.AspNetCore/JsonExceptionFilterAttribute.cs index 27ac4355ca..e40febea16 100644 --- a/src/NSwag.AspNetCore/JsonExceptionFilterAttribute.cs +++ b/src/NSwag.AspNetCore/JsonExceptionFilterAttribute.cs @@ -82,7 +82,7 @@ public override void OnActionExecuted(ActionExecutedContext context) } } - private int GetStatusCode(Exception exception, ActionExecutedContext context) + private static int GetStatusCode(Exception exception, ActionExecutedContext context) { if (context.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) { @@ -116,7 +116,7 @@ private int GetStatusCode(Exception exception, ActionExecutedContext context) return 500; } - private JsonSerializerSettings CopySettings(JsonSerializerSettings settings) + private static JsonSerializerSettings CopySettings(JsonSerializerSettings settings) { var settingsCopy = new JsonSerializerSettings(); diff --git a/src/NSwag.AspNetCore/Middlewares/RedirectToIndexMiddleware.cs b/src/NSwag.AspNetCore/Middlewares/RedirectToIndexMiddleware.cs index 28136dbc6c..0b0b706bbc 100644 --- a/src/NSwag.AspNetCore/Middlewares/RedirectToIndexMiddleware.cs +++ b/src/NSwag.AspNetCore/Middlewares/RedirectToIndexMiddleware.cs @@ -12,7 +12,7 @@ namespace NSwag.AspNetCore.Middlewares { - internal class RedirectToIndexMiddleware + internal sealed class RedirectToIndexMiddleware { private readonly RequestDelegate _nextDelegate; diff --git a/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs b/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs index 2889168a43..05efdc10e3 100644 --- a/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs +++ b/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs @@ -6,7 +6,7 @@ namespace NSwag.AspNetCore.Middlewares { - internal class SwaggerUiIndexMiddleware + internal sealed class SwaggerUiIndexMiddleware { private readonly RequestDelegate _nextDelegate; private readonly string _indexPath; diff --git a/src/NSwag.AspNetCore/OpenApiConfigureMvcOptions.cs b/src/NSwag.AspNetCore/OpenApiConfigureMvcOptions.cs index 76c8f17940..fc8ab7c231 100644 --- a/src/NSwag.AspNetCore/OpenApiConfigureMvcOptions.cs +++ b/src/NSwag.AspNetCore/OpenApiConfigureMvcOptions.cs @@ -11,7 +11,7 @@ namespace NSwag.AspNetCore { - internal class OpenApiConfigureMvcOptions : ConfigureOptions + internal sealed class OpenApiConfigureMvcOptions : ConfigureOptions { public OpenApiConfigureMvcOptions() : base(options => options.Conventions.Add(new OpenApiMvcApplicationModelConvention())) diff --git a/src/NSwag.AspNetCore/OpenApiDocumentProvider.cs b/src/NSwag.AspNetCore/OpenApiDocumentProvider.cs index 2c2585a579..7848fcdfc9 100644 --- a/src/NSwag.AspNetCore/OpenApiDocumentProvider.cs +++ b/src/NSwag.AspNetCore/OpenApiDocumentProvider.cs @@ -18,7 +18,7 @@ namespace NSwag.AspNetCore { - internal class OpenApiDocumentProvider : IDocumentProvider, IOpenApiDocumentGenerator + internal sealed class OpenApiDocumentProvider : IDocumentProvider, IOpenApiDocumentGenerator { private readonly IServiceProvider _serviceProvider; private readonly IEnumerable _documents; diff --git a/src/NSwag.AspNetCore/OpenApiMvcApplicationModelConvention.cs b/src/NSwag.AspNetCore/OpenApiMvcApplicationModelConvention.cs index 2b131b5dce..8176f86089 100644 --- a/src/NSwag.AspNetCore/OpenApiMvcApplicationModelConvention.cs +++ b/src/NSwag.AspNetCore/OpenApiMvcApplicationModelConvention.cs @@ -2,7 +2,7 @@ namespace NSwag.AspNetCore { - internal class OpenApiMvcApplicationModelConvention : IApplicationModelConvention + internal sealed class OpenApiMvcApplicationModelConvention : IApplicationModelConvention { public void Apply(ApplicationModel application) { diff --git a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs index ee5df125bd..52d9f300ca 100644 --- a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs +++ b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs @@ -122,7 +122,7 @@ protected string GetCustomScriptHtml(HttpRequest request) /// Generates the additional objects JavaScript code. /// The additional settings. /// The code. - protected string GenerateAdditionalSettings(IDictionary additionalSettings) + protected static string GenerateAdditionalSettings(IDictionary additionalSettings) { var code = ""; foreach (var pair in additionalSettings) diff --git a/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs b/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs index 9e59d42f77..75a3397025 100644 --- a/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs +++ b/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs @@ -252,7 +252,7 @@ public void When_the_generation_of_dto_classes_are_disabled_then_file_is_generat Assert.DoesNotContain("public partial class ComplexTypeResponse", code); } - private OpenApiDocument GetOpenApiDocument() + private static OpenApiDocument GetOpenApiDocument() { JsonSchema complexTypeSchema = new JsonSchema(); complexTypeSchema.Title = "ComplexType"; diff --git a/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs b/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs index 1964501515..cdaaf5b56e 100644 --- a/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs +++ b/src/NSwag.Commands/Commands/Document/CreateDocumentCommand.cs @@ -33,7 +33,7 @@ public async Task RunAsync(CommandLineProcessor processor, IConsoleHost return null; } - private async Task CreateDocumentAsync(string filePath) + private static async Task CreateDocumentAsync(string filePath) { var document = new NSwagDocument(); document.Path = filePath; diff --git a/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs b/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs index 3752d116e6..8c7c200c4f 100644 --- a/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs +++ b/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs @@ -15,7 +15,7 @@ namespace NSwag.Commands.Generation.AspNetCore { /// In-process entry point for the aspnetcore2swagger command. - internal class AspNetCoreToOpenApiGeneratorCommandEntryPoint + internal sealed class AspNetCoreToOpenApiGeneratorCommandEntryPoint { public static void Process(string commandContent, string outputFile, string applicationName) { diff --git a/src/NSwag.Commands/Commands/OutputCommandBase.cs b/src/NSwag.Commands/Commands/OutputCommandBase.cs index 2549ab4b07..0f5a67419a 100644 --- a/src/NSwag.Commands/Commands/OutputCommandBase.cs +++ b/src/NSwag.Commands/Commands/OutputCommandBase.cs @@ -25,7 +25,7 @@ public abstract class OutputCommandBase : IOutputCommand public abstract Task RunAsync(CommandLineProcessor processor, IConsoleHost host); - protected Task ReadSwaggerDocumentAsync(string input) + protected static Task ReadSwaggerDocumentAsync(string input) { if (!IsJson(input) && !IsYaml(input)) { @@ -67,12 +67,12 @@ protected Task ReadSwaggerDocumentAsync(string input) } } - protected bool IsJson(string data) + protected static bool IsJson(string data) { return data.StartsWith("{"); } - protected bool IsYaml(string data) + protected static bool IsYaml(string data) { return !IsJson(data) && data.Contains("\n"); } diff --git a/src/NSwag.Commands/HostApplication.cs b/src/NSwag.Commands/HostApplication.cs index 0f17e87551..0361c92123 100644 --- a/src/NSwag.Commands/HostApplication.cs +++ b/src/NSwag.Commands/HostApplication.cs @@ -181,13 +181,13 @@ void OnEntryPointExit(Exception exception) #endif } - private class NoopHostLifetime : IHostLifetime + private sealed class NoopHostLifetime : IHostLifetime { public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; public Task WaitForStartAsync(CancellationToken cancellationToken) => Task.CompletedTask; } - private class NoopServer : IServer + private sealed class NoopServer : IServer { public IFeatureCollection Features { get; } = new FeatureCollection(); public void Dispose() { } diff --git a/src/NSwag.Commands/NSwagDocument.cs b/src/NSwag.Commands/NSwagDocument.cs index e4fba7315d..f5885f9efd 100644 --- a/src/NSwag.Commands/NSwagDocument.cs +++ b/src/NSwag.Commands/NSwagDocument.cs @@ -230,11 +230,13 @@ private async Task StartCommandLineProcessAsync(string command) private string GetDocumentDirectory() { - var absoluteDocumentPath = PathUtilities.MakeAbsolutePath(Path, System.IO.Directory.GetCurrentDirectory()); + var absoluteDocumentPath = PathUtilities.MakeAbsolutePath(Path, Directory.GetCurrentDirectory()); return System.IO.Path.GetDirectoryName(absoluteDocumentPath); } +#pragma warning disable CA1822 private string GetArgumentsPrefix() +#pragma warning restore CA1822 { #if NET462 @@ -252,7 +254,9 @@ private string GetArgumentsPrefix() return ""; } +#pragma warning disable CA1822 private string GetProgramName() +#pragma warning restore CA1822 { #if NET462 @@ -270,7 +274,7 @@ private string GetProgramName() return "dotnet"; } - private string ReadFileIfExists(string filename) + private static string ReadFileIfExists(string filename) { if (filename != null && File.Exists(filename)) { @@ -280,7 +284,7 @@ private string ReadFileIfExists(string filename) return null; } - private void DeleteFileIfExists(string filename) + private static void DeleteFileIfExists(string filename) { if (File.Exists(filename)) { @@ -288,7 +292,7 @@ private void DeleteFileIfExists(string filename) } } - internal class CommandLineException : Exception + private sealed class CommandLineException : Exception { public CommandLineException(string message, string stackTrace) : base(message) diff --git a/src/NSwag.Commands/OperationGenerationModeConverter.cs b/src/NSwag.Commands/OperationGenerationModeConverter.cs index 1e60cff0c7..e8b130c1dd 100644 --- a/src/NSwag.Commands/OperationGenerationModeConverter.cs +++ b/src/NSwag.Commands/OperationGenerationModeConverter.cs @@ -11,7 +11,7 @@ namespace NSwag.Commands { - internal class OperationGenerationModeConverter + internal sealed class OperationGenerationModeConverter { internal static OperationGenerationMode GetOperationGenerationMode(IOperationNameGenerator operationNameGenerator) { diff --git a/src/NSwag.Core.Tests/Serialization/PathItemTests.cs b/src/NSwag.Core.Tests/Serialization/PathItemTests.cs index acb89f1e43..16affc0735 100644 --- a/src/NSwag.Core.Tests/Serialization/PathItemTests.cs +++ b/src/NSwag.Core.Tests/Serialization/PathItemTests.cs @@ -24,7 +24,7 @@ public async Task PathItem_With_External_Ref_Can_Be_Serialized() Assert.True(getOperation.ActualResponses.ContainsKey("200")); } - private string GetTestDirectory() + private static string GetTestDirectory() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); diff --git a/src/NSwag.Core.Yaml.Tests/References/YamlReferencesTests.cs b/src/NSwag.Core.Yaml.Tests/References/YamlReferencesTests.cs index 3854da4eb3..9fecc0f538 100644 --- a/src/NSwag.Core.Yaml.Tests/References/YamlReferencesTests.cs +++ b/src/NSwag.Core.Yaml.Tests/References/YamlReferencesTests.cs @@ -29,7 +29,7 @@ public async Task When_yaml_schema_has_references_it_works(string relativePath) Assert.Equal(JsonObjectType.Boolean, document.Definitions["ContractObject"].Properties["bar"].ActualTypeSchema.Type); } - private string GetTestDirectory() + private static string GetTestDirectory() { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var uri = new UriBuilder(codeBase); diff --git a/src/NSwag.Core/OpenApiDocument.cs b/src/NSwag.Core/OpenApiDocument.cs index b915a5c1ba..21b4a35562 100644 --- a/src/NSwag.Core/OpenApiDocument.cs +++ b/src/NSwag.Core/OpenApiDocument.cs @@ -329,7 +329,7 @@ public void GenerateOperationIds() } } - private string GetOperationNameFromPath(OpenApiOperationDescription operation) + private static string GetOperationNameFromPath(OpenApiOperationDescription operation) { var pathSegments = operation.Path.Trim('/').Split('/'); var lastPathSegment = pathSegments.LastOrDefault(s => !s.Contains("{")); diff --git a/src/NSwag.Core/OpenApiPathItem.cs b/src/NSwag.Core/OpenApiPathItem.cs index 5b5afa3c6d..d0e648adba 100644 --- a/src/NSwag.Core/OpenApiPathItem.cs +++ b/src/NSwag.Core/OpenApiPathItem.cs @@ -104,7 +104,7 @@ IJsonReference IJsonReferenceBase.Reference #endregion // Needed to convert dictionary keys to lower case - internal class OpenApiPathItemConverter : JsonConverter + internal sealed class OpenApiPathItemConverter : JsonConverter { public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { diff --git a/src/NSwag.Generation.AspNetCore.Tests/Processors/OperationResponseProcessorTest.cs b/src/NSwag.Generation.AspNetCore.Tests/Processors/OperationResponseProcessorTest.cs index 994f0ef7f8..fc20775a11 100644 --- a/src/NSwag.Generation.AspNetCore.Tests/Processors/OperationResponseProcessorTest.cs +++ b/src/NSwag.Generation.AspNetCore.Tests/Processors/OperationResponseProcessorTest.cs @@ -148,8 +148,10 @@ private AspNetCoreOperationProcessorContext GetContext(ApiDescription apiDescrip return context; } - private class TestModel { } + private sealed class TestModel { } +#pragma warning disable CA1822 private TestModel SomeAction() => null; +#pragma warning restore CA1822 } } diff --git a/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs b/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs index 7b1ac66ecf..62337c1263 100644 --- a/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs +++ b/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs @@ -290,7 +290,7 @@ private List GenerateApiGroups( return usedControllerTypes; } - private bool IsOperationDeprecated(ApiDescription apiDescription, ActionDescriptor actionDescriptor, MethodInfo methodInfo) + private static bool IsOperationDeprecated(ApiDescription apiDescription, ActionDescriptor actionDescriptor, MethodInfo methodInfo) { if (methodInfo?.GetCustomAttribute() != null) { diff --git a/src/NSwag.Generation.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.Generation.AspNetCore/Processors/OperationParameterProcessor.cs index 7cf08d1806..349dceab07 100644 --- a/src/NSwag.Generation.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.Generation.AspNetCore/Processors/OperationParameterProcessor.cs @@ -24,7 +24,7 @@ namespace NSwag.Generation.AspNetCore.Processors { - internal class OperationParameterProcessor : IOperationProcessor + internal sealed class OperationParameterProcessor : IOperationProcessor { private const string MultipartFormData = "multipart/form-data"; @@ -247,7 +247,7 @@ private void ApplyOpenApiBodyParameterAttribute(OpenApiOperationDescription oper } } - private void EnsureSingleBodyParameter(OpenApiOperationDescription operationDescription) + private static void EnsureSingleBodyParameter(OpenApiOperationDescription operationDescription) { if (operationDescription.Operation.ActualParameters.Count(p => p.Kind == OpenApiParameterKind.Body) > 1) { @@ -255,7 +255,7 @@ private void EnsureSingleBodyParameter(OpenApiOperationDescription operationDesc } } - private void UpdateConsumedTypes(OpenApiOperationDescription operationDescription) + private static void UpdateConsumedTypes(OpenApiOperationDescription operationDescription) { if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary || p.ActualSchema.IsBinary)) { @@ -263,7 +263,7 @@ private void UpdateConsumedTypes(OpenApiOperationDescription operationDescriptio } } - private void RemoveUnusedPathParameters(OpenApiOperationDescription operationDescription, string httpPath) + private static void RemoveUnusedPathParameters(OpenApiOperationDescription operationDescription, string httpPath) { operationDescription.Path = "/" + Regex.Replace(httpPath, "{(.*?)(:(([^/]*)?))?}", match => { @@ -324,7 +324,7 @@ private void AddFileParameter(OperationProcessorContext context, ExtendedApiPara } } - private JsonSchema CreateOrGetFormDataSchema(OperationProcessorContext context) + private static JsonSchema CreateOrGetFormDataSchema(OperationProcessorContext context) { if (context.OperationDescription.Operation.RequestBody == null) { @@ -501,7 +501,7 @@ private OpenApiParameter CreatePrimitiveParameter( return operationParameter; } - private class ExtendedApiParameterDescription + private sealed class ExtendedApiParameterDescription { private readonly IXmlDocsSettings _xmlDocsSettings; diff --git a/src/NSwag.Generation.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.Generation.AspNetCore/Processors/OperationResponseProcessor.cs index bf8cd3c5cb..597cadd525 100644 --- a/src/NSwag.Generation.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.Generation.AspNetCore/Processors/OperationResponseProcessor.cs @@ -119,7 +119,7 @@ protected override string GetVoidResponseStatusCode() return "200"; } - private bool IsVoidResponse(Type returnType) + private static bool IsVoidResponse(Type returnType) { return returnType == null || returnType.FullName == "System.Void"; } diff --git a/src/NSwag.Generation.WebApi/Infrastructure/RouteAttributeFacade.cs b/src/NSwag.Generation.WebApi/Infrastructure/RouteAttributeFacade.cs index 149dfaf94f..d15e374ccb 100644 --- a/src/NSwag.Generation.WebApi/Infrastructure/RouteAttributeFacade.cs +++ b/src/NSwag.Generation.WebApi/Infrastructure/RouteAttributeFacade.cs @@ -18,7 +18,7 @@ namespace NSwag.Generation.WebApi.Infrastructure /// * IHttpRouteInfoProvider /// * IRouteTemplateProvider /// - internal class RouteAttributeFacade + internal sealed class RouteAttributeFacade { private readonly PropertyInfo _template; diff --git a/src/NSwag.Generation.WebApi/Infrastructure/RoutePrefixAttributeFacade.cs b/src/NSwag.Generation.WebApi/Infrastructure/RoutePrefixAttributeFacade.cs index faadfb0c51..6e7fe6b2db 100644 --- a/src/NSwag.Generation.WebApi/Infrastructure/RoutePrefixAttributeFacade.cs +++ b/src/NSwag.Generation.WebApi/Infrastructure/RoutePrefixAttributeFacade.cs @@ -17,7 +17,7 @@ namespace NSwag.Generation.WebApi.Infrastructure /// * RoutePrefixAttribute /// * IRoutePrefix /// - internal class RoutePrefixAttributeFacade + internal sealed class RoutePrefixAttributeFacade { private readonly PropertyInfo _prefix; diff --git a/src/NSwag.Generation.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.Generation.WebApi/Processors/OperationParameterProcessor.cs index 9521d52db1..09b69b2d62 100644 --- a/src/NSwag.Generation.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.Generation.WebApi/Processors/OperationParameterProcessor.cs @@ -258,7 +258,7 @@ private void ApplyOpenApiBodyParameterAttribute(OpenApiOperationDescription oper /// /// Operation to check. /// Schema type. - private void UpdateNullableRawOperationParameters(OpenApiOperationDescription operationDescription, SchemaType schemaType) + private static void UpdateNullableRawOperationParameters(OpenApiOperationDescription operationDescription, SchemaType schemaType) { if (schemaType == SchemaType.OpenApi3) { @@ -269,7 +269,7 @@ private void UpdateNullableRawOperationParameters(OpenApiOperationDescription op } } - private void EnsureSingleBodyParameter(OpenApiOperationDescription operationDescription) + private static void EnsureSingleBodyParameter(OpenApiOperationDescription operationDescription) { if (operationDescription.Operation.ActualParameters.Count(p => p.Kind == OpenApiParameterKind.Body) > 1) { @@ -277,7 +277,7 @@ private void EnsureSingleBodyParameter(OpenApiOperationDescription operationDesc } } - private void UpdateConsumedTypes(OpenApiOperationDescription operationDescription) + private static void UpdateConsumedTypes(OpenApiOperationDescription operationDescription) { if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary || p.ActualSchema.IsBinary)) { @@ -285,7 +285,7 @@ private void UpdateConsumedTypes(OpenApiOperationDescription operationDescriptio } } - private void RemoveUnusedPathParameters(OpenApiOperationDescription operationDescription, string httpPath) + private static void RemoveUnusedPathParameters(OpenApiOperationDescription operationDescription, string httpPath) { operationDescription.Path = Regex.Replace(httpPath, "{(.*?)(:(([^/]*)?))?}", match => { @@ -524,7 +524,7 @@ private OpenApiParameter AddPrimitiveParameter( return operationParameter; } - private void InitializeFileParameter(OpenApiParameter operationParameter, bool isFileArray) + private static void InitializeFileParameter(OpenApiParameter operationParameter, bool isFileArray) { operationParameter.Type = JsonObjectType.File; operationParameter.Kind = OpenApiParameterKind.FormData; diff --git a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs index 278bb1d4da..feff0bf4ee 100644 --- a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs +++ b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs @@ -424,7 +424,7 @@ private List GetHttpPaths(Type controllerType, MethodInfo method) .ToList(); } - private IEnumerable ExpandOptionalHttpPathParameters(string path, MethodInfo method) + private static IEnumerable ExpandOptionalHttpPathParameters(string path, MethodInfo method) { var segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < segments.Length; i++) @@ -455,7 +455,7 @@ private IEnumerable ExpandOptionalHttpPathParameters(string path, Method yield return path; } - private IEnumerable GetAllRouteAttributes(Type type) + private static IEnumerable GetAllRouteAttributes(Type type) { do { @@ -473,7 +473,7 @@ private IEnumerable GetAllRouteAttributes(Type type) return null; } - private RoutePrefixAttributeFacade GetRoutePrefixAttribute(Type type) + private static RoutePrefixAttributeFacade GetRoutePrefixAttribute(Type type) { do { @@ -491,17 +491,17 @@ private RoutePrefixAttributeFacade GetRoutePrefixAttribute(Type type) return null; } - private IEnumerable GetRouteAttributes(IEnumerable attributes) + private static IEnumerable GetRouteAttributes(IEnumerable attributes) { return attributes.Select(RouteAttributeFacade.TryMake).Where(a => a?.Template != null); } - private IEnumerable GetRoutePrefixAttributes(IEnumerable attributes) + private static IEnumerable GetRoutePrefixAttributes(IEnumerable attributes) { return attributes.Select(RoutePrefixAttributeFacade.TryMake).Where(a => a != null); } - private string GetActionName(MethodInfo method) + private static string GetActionName(MethodInfo method) { dynamic actionNameAttribute = method.GetCustomAttributes() .SingleOrDefault(a => a.GetType().Name == "ActionNameAttribute"); @@ -520,7 +520,7 @@ private string GetActionName(MethodInfo method) return methodName; } - private IEnumerable GetSupportedHttpMethods(MethodInfo method) + private static IEnumerable GetSupportedHttpMethods(MethodInfo method) { // See http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api @@ -569,7 +569,7 @@ private IEnumerable GetSupportedHttpMethods(MethodInfo method) } } - private IEnumerable GetSupportedHttpMethodsFromAttributes(MethodInfo method) + private static IEnumerable GetSupportedHttpMethodsFromAttributes(MethodInfo method) { if (method.GetCustomAttributes().Any(a => a.GetType().Name == "HttpGetAttribute")) { diff --git a/src/NSwag.Generation/OpenApiSchemaGenerator.cs b/src/NSwag.Generation/OpenApiSchemaGenerator.cs index eb1ebc906f..0c1ab63e7f 100644 --- a/src/NSwag.Generation/OpenApiSchemaGenerator.cs +++ b/src/NSwag.Generation/OpenApiSchemaGenerator.cs @@ -81,7 +81,7 @@ public override TSchemaType GenerateWithReferenceAndNullability( return base.GenerateWithReferenceAndNullability(contextualType, isNullable, schemaResolver, transformation); } - private bool IsFileResponse(Type returnType) + private static bool IsFileResponse(Type returnType) { return returnType.IsAssignableToTypeName("FileResult", TypeNameStyle.Name) || returnType.Name == "IActionResult" || diff --git a/src/NSwag.Generation/Processors/ApiVersionProcessor.cs b/src/NSwag.Generation/Processors/ApiVersionProcessor.cs index f917259d95..57e3f1dfd5 100644 --- a/src/NSwag.Generation/Processors/ApiVersionProcessor.cs +++ b/src/NSwag.Generation/Processors/ApiVersionProcessor.cs @@ -75,7 +75,7 @@ public bool Process(OperationProcessorContext context) } } - private bool UseVersionedApiExplorer(OperationProcessorContext context) + private static bool UseVersionedApiExplorer(OperationProcessorContext context) { if (context.HasProperty("ApiDescription")) { @@ -89,14 +89,14 @@ private bool UseVersionedApiExplorer(OperationProcessorContext context) return false; } - private void RemoveApiVersionPathParameter(OperationProcessorContext context, string version) + private static void RemoveApiVersionPathParameter(OperationProcessorContext context, string version) { var operationDescription = context.OperationDescription; operationDescription.Path = operationDescription.Path.Replace("{version:apiVersion}", version); operationDescription.Path = operationDescription.Path.Replace("{version}", version); } - private string[] GetVersions(OperationProcessorContext context, string attributeType) + private static string[] GetVersions(OperationProcessorContext context, string attributeType) { var versionAttributes = context.MethodInfo.GetCustomAttributes() .Concat(context.MethodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes()) diff --git a/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs b/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs index 7e2837780f..aec0b38db9 100644 --- a/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.Generation/Processors/OperationResponseProcessorBase.cs @@ -297,7 +297,7 @@ private void LoadDefaultSuccessResponse(ParameterInfo returnParameter, string su } } - private bool IsVoidResponse(Type returnType) + private static bool IsVoidResponse(Type returnType) { return returnType == null || returnType.FullName == "System.Void"; } diff --git a/src/NSwag.Generation/Processors/OperationSummaryAndDescriptionProcessor.cs b/src/NSwag.Generation/Processors/OperationSummaryAndDescriptionProcessor.cs index dba3ec6881..443ce35685 100644 --- a/src/NSwag.Generation/Processors/OperationSummaryAndDescriptionProcessor.cs +++ b/src/NSwag.Generation/Processors/OperationSummaryAndDescriptionProcessor.cs @@ -32,7 +32,7 @@ public bool Process(OperationProcessorContext context) return true; } - private void ProcessSummary(OperationProcessorContext context, Attribute[] attributes) + private static void ProcessSummary(OperationProcessorContext context, Attribute[] attributes) { dynamic openApiOperationAttribute = attributes .SingleOrDefault(a => a.GetType().Name == "OpenApiOperationAttribute"); @@ -58,7 +58,7 @@ private void ProcessSummary(OperationProcessorContext context, Attribute[] attri } } - private void ProcessDescription(OperationProcessorContext context, Attribute[] attributes) + private static void ProcessDescription(OperationProcessorContext context, Attribute[] attributes) { dynamic openApiOperationAttribute = attributes .SingleOrDefault(a => a.GetType().Name == "OpenApiOperationAttribute"); diff --git a/src/NSwag.Generation/Processors/OperationTagsProcessor.cs b/src/NSwag.Generation/Processors/OperationTagsProcessor.cs index b652f8a3ad..961cfc20fd 100644 --- a/src/NSwag.Generation/Processors/OperationTagsProcessor.cs +++ b/src/NSwag.Generation/Processors/OperationTagsProcessor.cs @@ -70,7 +70,7 @@ protected virtual void AddControllerNameTag(OperationProcessorContext context) /// The context. /// The tag name. /// The description. - protected void UpdateDocumentTagDescription(OperationProcessorContext context, string tagName, string description) + protected static void UpdateDocumentTagDescription(OperationProcessorContext context, string tagName, string description) { if (!context.Settings.UseControllerSummaryAsTagDescription || string.IsNullOrEmpty(description)) { @@ -82,7 +82,7 @@ protected void UpdateDocumentTagDescription(OperationProcessorContext context, s documentTag.Description = description; } - private void ProcessSwaggerTagAttributes(OpenApiDocument document, OpenApiOperationDescription operationDescription, MethodInfo methodInfo) + private static void ProcessSwaggerTagAttributes(OpenApiDocument document, OpenApiOperationDescription operationDescription, MethodInfo methodInfo) { foreach (var tagAttribute in methodInfo.GetCustomAttributes() .GetAssignableToTypeName("SwaggerTagAttribute", TypeNameStyle.Name) @@ -100,7 +100,7 @@ private void ProcessSwaggerTagAttributes(OpenApiDocument document, OpenApiOperat } } - private void ProcessSwaggerTagsAttribute(OpenApiDocument document, OpenApiOperationDescription operationDescription, MethodInfo methodInfo) + private static void ProcessSwaggerTagsAttribute(OpenApiDocument document, OpenApiOperationDescription operationDescription, MethodInfo methodInfo) { dynamic tagsAttribute = methodInfo .GetCustomAttributes() @@ -132,7 +132,7 @@ private void ProcessSwaggerTagsAttribute(OpenApiDocument document, OpenApiOperat } } - private void ProcessControllerSwaggerTagsAttribute(OpenApiOperationDescription operationDescription, TypeInfo typeInfo) + private static void ProcessControllerSwaggerTagsAttribute(OpenApiOperationDescription operationDescription, TypeInfo typeInfo) { dynamic tagsAttribute = typeInfo .GetCustomAttributes() @@ -151,7 +151,7 @@ private void ProcessControllerSwaggerTagsAttribute(OpenApiOperationDescription o } } - private void ProcessControllerSwaggerTagAttributes(OpenApiOperationDescription operationDescription, TypeInfo typeInfo) + private static void ProcessControllerSwaggerTagAttributes(OpenApiOperationDescription operationDescription, TypeInfo typeInfo) { foreach (var tagAttribute in typeInfo.GetCustomAttributes() .GetAssignableToTypeName("OpenApiTagAttribute", TypeNameStyle.Name)