From c76eaa1dfb1321811e0c96a47c5f5393054ced0f Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 13:20:04 +0200 Subject: [PATCH 1/7] fix: Remove as this in some cases prevents meaningful operationId naming. --- .../OpenApiDocumentValidationHelper.cs | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs index 1473277e6..6e797174e 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs @@ -239,31 +239,6 @@ private static List<LogKeyValueItem> ValidateOperations( } } } - - foreach (var (operationKey, operationValue) in pathValue.Operations) - { - // Validate Response Schema - var responseModelSchema = operationValue.GetModelSchemaFromResponse(); - if (responseModelSchema is not null) - { - if (operationValue.IsOperationIdPluralized(operationKey)) - { - if (!IsModelOfTypeArray(responseModelSchema, modelSchemas)) - { - logItems.Add(LogItemHelper.Create(logCategory, ValidationRuleNameConstants.Operation08, $"OperationId '{operationValue.OperationId}' is not singular - Response model is defined as a single item.")); - } - } - else - { - if (IsModelOfTypeArray(responseModelSchema, modelSchemas)) - { - logItems.Add(LogItemHelper.Create(logCategory, ValidationRuleNameConstants.Operation09, $"OperationId '{operationValue.OperationId}' is not pluralized - Response model is defined as an array.")); - } - } - } - - //// TO-DO Validate RequestBody Schema - } } return logItems; From 180fd720138a4679e8ea779067a82e9da0f7f4bf Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 14:03:09 +0200 Subject: [PATCH 2/7] chore: Update nuget packages. --- .../Helpers/NugetPackageReferenceHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs index d96e566a4..3d4fe76b7 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs @@ -16,12 +16,12 @@ public static class NugetPackageReferenceHelper if (useRestExtended) { packageReference.Add(new Tuple<string, string, string?>("Atc.Rest.Extended", atcVersion, null)); - packageReference.Add(new Tuple<string, string, string?>("FluentValidation.AspNetCore", "11.0.0", null)); - packageReference.Add(new Tuple<string, string, string?>("Microsoft.ApplicationInsights.AspNetCore", "2.20.0", null)); - packageReference.Add(new Tuple<string, string, string?>("Microsoft.AspNetCore.Authentication.JwtBearer", "6.0.4", null)); + packageReference.Add(new Tuple<string, string, string?>("FluentValidation.AspNetCore", "11.1.3", null)); + packageReference.Add(new Tuple<string, string, string?>("Microsoft.ApplicationInsights.AspNetCore", "2.21.0", null)); + packageReference.Add(new Tuple<string, string, string?>("Microsoft.AspNetCore.Authentication.JwtBearer", "6.0.7", null)); packageReference.Add(new Tuple<string, string, string?>("Microsoft.AspNetCore.Mvc.Versioning", "5.0.0", null)); packageReference.Add(new Tuple<string, string, string?>("Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer", "5.0.0", null)); - packageReference.Add(new Tuple<string, string, string?>("Swashbuckle.AspNetCore", "6.3.1", null)); + packageReference.Add(new Tuple<string, string, string?>("Swashbuckle.AspNetCore", "6.4.0", null)); } return packageReference; From 273865ef919e070f61259066e7194df387ee7129 Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 14:33:27 +0200 Subject: [PATCH 3/7] chore: Reintroduce todo. --- .../Helpers/OpenApiDocumentValidationHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs index 6e797174e..fa6b535b5 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs @@ -239,6 +239,8 @@ private static List<LogKeyValueItem> ValidateOperations( } } } + + //// TO-DO Validate RequestBody Schema } return logItems; From 0c1dad0e8591e4c4caa2dc1d8b253db35d17b93e Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 15:26:25 +0200 Subject: [PATCH 4/7] feat: Make it optional to do operationId validation for plural case. --- .../ApiOptionsHelper.cs | 5 ++++ .../Commands/ArgumentCommandConstants.cs | 1 + .../BaseConfigurationCommandSettings.cs | 10 +++++-- .../OpenApiDocumentValidationHelper.cs | 28 ++++++++++++++++++- .../Models/Options/ApiOptionsValidation.cs | 2 ++ 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs b/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs index ccf8a21b0..a8e056a3f 100644 --- a/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs +++ b/src/Atc.Rest.ApiGenerator.CLI/ApiOptionsHelper.cs @@ -96,6 +96,11 @@ private static void ApplyValidationOverrides( apiOptions.Validation.StrictMode = settings.StrictMode; } + if (settings.OperationIdValidation) + { + apiOptions.Validation.OperationIdValidation = settings.OperationIdValidation; + } + if (settings.OperationIdCasingStyle.IsSet) { apiOptions.Validation.OperationIdCasingStyle = settings.OperationIdCasingStyle.Value; diff --git a/src/Atc.Rest.ApiGenerator.CLI/Commands/ArgumentCommandConstants.cs b/src/Atc.Rest.ApiGenerator.CLI/Commands/ArgumentCommandConstants.cs index 1dc7c592d..9b5907327 100644 --- a/src/Atc.Rest.ApiGenerator.CLI/Commands/ArgumentCommandConstants.cs +++ b/src/Atc.Rest.ApiGenerator.CLI/Commands/ArgumentCommandConstants.cs @@ -13,6 +13,7 @@ public static class ArgumentCommandConstants public const string LongConfigurationAuthorization = "--useAuthorization"; public const string LongConfigurationValidateStrictMode = "--validate-strictMode"; + public const string LongConfigurationValidateOperationIdValidation = "--validate-operationIdValidation"; public const string LongConfigurationValidateOperationIdCasingStyle = "--validate-operationIdCasingStyle"; public const string LongConfigurationValidateModelNameCasingStyle = "--validate-modelNameCasingStyle"; public const string LongConfigurationValidateModelPropertyNameCasingStyle = "--validate-modelPropertyNameCasingStyle"; diff --git a/src/Atc.Rest.ApiGenerator.CLI/Commands/Settings/BaseConfigurationCommandSettings.cs b/src/Atc.Rest.ApiGenerator.CLI/Commands/Settings/BaseConfigurationCommandSettings.cs index b73dc902f..ffdd62d1f 100644 --- a/src/Atc.Rest.ApiGenerator.CLI/Commands/Settings/BaseConfigurationCommandSettings.cs +++ b/src/Atc.Rest.ApiGenerator.CLI/Commands/Settings/BaseConfigurationCommandSettings.cs @@ -14,17 +14,21 @@ public class BaseConfigurationCommandSettings : BaseCommandSettings [Description("Use strictmode")] public bool StrictMode { get; init; } + [CommandOption($"{ArgumentCommandConstants.LongConfigurationValidateOperationIdValidation}")] + [Description("Use operationId validation")] + public bool OperationIdValidation { get; init; } + [CommandOption($"{ArgumentCommandConstants.LongConfigurationValidateOperationIdCasingStyle} [OPERATIONIDCASINGSTYLE]")] [CasingStyleDescription(Default = CasingStyle.CamelCase, Prefix = "Set casingStyle for operationId")] - public FlagValue<CasingStyle> OperationIdCasingStyle { get; init; } = new (); + public FlagValue<CasingStyle> OperationIdCasingStyle { get; init; } = new(); [CommandOption($"{ArgumentCommandConstants.LongConfigurationValidateModelNameCasingStyle} [MODELNAMECASINGSTYLE]")] [CasingStyleDescription(Default = CasingStyle.PascalCase, Prefix = "Set casingStyle for model name")] - public FlagValue<CasingStyle> ModelNameCasingStyle { get; init; } = new (); + public FlagValue<CasingStyle> ModelNameCasingStyle { get; init; } = new(); [CommandOption($"{ArgumentCommandConstants.LongConfigurationValidateModelPropertyNameCasingStyle} [MODELPROPERTYNAMECASINGSTYLE]")] [CasingStyleDescription(Default = CasingStyle.CamelCase, Prefix = "Set casingStyle for model property name")] - public FlagValue<CasingStyle> ModelPropertyNameCasingStyle { get; init; } = new (); + public FlagValue<CasingStyle> ModelPropertyNameCasingStyle { get; init; } = new(); [CommandOption($"{ArgumentCommandConstants.LongConfigurationAuthorization}")] [Description("Use authorization")] diff --git a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs index fa6b535b5..73a346130 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentValidationHelper.cs @@ -240,7 +240,33 @@ private static List<LogKeyValueItem> ValidateOperations( } } - //// TO-DO Validate RequestBody Schema + if (validationOptions.OperationIdValidation) + { + foreach (var (operationKey, operationValue) in pathValue.Operations) + { + // Validate Response Schema + var responseModelSchema = operationValue.GetModelSchemaFromResponse(); + if (responseModelSchema is not null) + { + if (operationValue.IsOperationIdPluralized(operationKey)) + { + if (!IsModelOfTypeArray(responseModelSchema, modelSchemas)) + { + logItems.Add(LogItemHelper.Create(logCategory, ValidationRuleNameConstants.Operation08, $"OperationId '{operationValue.OperationId}' is not singular - Response model is defined as a single item.")); + } + } + else + { + if (IsModelOfTypeArray(responseModelSchema, modelSchemas)) + { + logItems.Add(LogItemHelper.Create(logCategory, ValidationRuleNameConstants.Operation09, $"OperationId '{operationValue.OperationId}' is not pluralized - Response model is defined as an array.")); + } + } + } + + //// TO-DO Validate RequestBody Schema + } + } } return logItems; diff --git a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsValidation.cs b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsValidation.cs index f427ec089..dc34222d0 100644 --- a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsValidation.cs +++ b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsValidation.cs @@ -6,6 +6,8 @@ public class ApiOptionsValidation { public bool StrictMode { get; set; } + public bool OperationIdValidation { get; set; } + public CasingStyle OperationIdCasingStyle { get; set; } = CasingStyle.CamelCase; public CasingStyle ModelNameCasingStyle { get; set; } = CasingStyle.PascalCase; From 319bfe79d7d6fb1275953466858e289deb94285b Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 15:32:40 +0200 Subject: [PATCH 5/7] chore: Update Stylecop. --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 6fc6302bf..2b8eb24b7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -45,7 +45,7 @@ <PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" /> <PackageReference Include="Meziantou.Analyzer" Version="1.0.701" PrivateAssets="All" /> <PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.2" PrivateAssets="All" /> - <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" /> + <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" /> <PackageReference Include="SonarAnalyzer.CSharp" Version="8.38.0.46746" PrivateAssets="All" /> </ItemGroup> From 9d62fc973cd7eb497784a252ca8d027e3845a3a8 Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 15:47:50 +0200 Subject: [PATCH 6/7] chore: updated Analysers and ignored SA1414. --- .editorconfig | 4 +++- Directory.Build.props | 6 +++--- .../AtcApiNugetClientHelper.cs | 2 +- .../PropertyDeclarationSyntaxExtensions.cs | 4 ++-- .../Extensions/StringExtensions.cs | 20 +++++++++---------- .../SuppressMessageAttributeFactory.cs | 2 +- .../Helpers/AtcApiNugetClientHelper.cs | 2 +- .../Helpers/GenerateCodeHelper.cs | 2 +- .../Helpers/GenerateHelper.cs | 2 +- .../Helpers/HttpClientHelper.cs | 4 +--- .../Helpers/OpenApiDocumentHelper.cs | 2 +- ...ateServerApiXunitTestEndpointTestHelper.cs | 2 +- .../XunitTest/GenerateXunitTestPartsHelper.cs | 2 +- .../ValueTypeTestPropertiesHelper.cs | 4 ++-- .../Models/Options/ApiOptions.cs | 4 ++-- .../Models/Options/ApiOptionsGenerator.cs | 4 ++-- .../SyntaxDocumentationFactory.cs | 2 +- .../SyntaxPropertyDeclarationFactory.cs | 2 +- .../SyntaxGeneratorClientEndpoint.cs | 2 +- .../Domain/SyntaxGeneratorHandler.cs | 3 ++- .../CodeComplianceTests.cs | 2 +- .../CodeDocumentationTests.cs | 3 ++- 22 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.editorconfig b/.editorconfig index 364e571b3..09abcd6ad 100644 --- a/.editorconfig +++ b/.editorconfig @@ -513,4 +513,6 @@ dotnet_diagnostic.CA1848.severity = suggestion # Use the LoggerMessage delegate dotnet_diagnostic.CA2254.severity = suggestion # Template should be a static expression - https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2254 dotnet_diagnostic.S1172.severity = none # False positive -dotnet_diagnostic.S3267.severity = none # Loop should be simplified by calling Select(x => x.Value)) - We dont like this rule because of readability/maintainability \ No newline at end of file +dotnet_diagnostic.S3267.severity = none # Loop should be simplified by calling Select(x => x.Value)) - We dont like this rule because of readability/maintainability + +dotnet_diagnostic.SA1414.Severity = none # Tuple types in signatures should have element names \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 2b8eb24b7..9f9bf2a5e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -43,10 +43,10 @@ <ItemGroup Label="Code Analyzers"> <PackageReference Include="AsyncFixer" Version="1.5.1" PrivateAssets="All" /> <PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" /> - <PackageReference Include="Meziantou.Analyzer" Version="1.0.701" PrivateAssets="All" /> - <PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.2" PrivateAssets="All" /> + <PackageReference Include="Meziantou.Analyzer" Version="1.0.717" PrivateAssets="All" /> + <PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.6" PrivateAssets="All" /> <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435" PrivateAssets="All" /> - <PackageReference Include="SonarAnalyzer.CSharp" Version="8.38.0.46746" PrivateAssets="All" /> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.44.0.52574" PrivateAssets="All" /> </ItemGroup> </Project> \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator.CLI/AtcApiNugetClientHelper.cs b/src/Atc.Rest.ApiGenerator.CLI/AtcApiNugetClientHelper.cs index 1fb781f56..aa1a50622 100644 --- a/src/Atc.Rest.ApiGenerator.CLI/AtcApiNugetClientHelper.cs +++ b/src/Atc.Rest.ApiGenerator.CLI/AtcApiNugetClientHelper.cs @@ -3,7 +3,7 @@ namespace Atc.Rest.ApiGenerator.CLI; public static class AtcApiNugetClientHelper { private const string BaseAddress = "https://atc-api.azurewebsites.net/nuget-search"; - private static readonly ConcurrentDictionary<string, Version> Cache = new (StringComparer.Ordinal); + private static readonly ConcurrentDictionary<string, Version> Cache = new(StringComparer.Ordinal); [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "OK.")] public static Version? GetLatestVersionForPackageId( diff --git a/src/Atc.Rest.ApiGenerator/Extensions/PropertyDeclarationSyntaxExtensions.cs b/src/Atc.Rest.ApiGenerator/Extensions/PropertyDeclarationSyntaxExtensions.cs index 986ee1f74..afa40f1f5 100644 --- a/src/Atc.Rest.ApiGenerator/Extensions/PropertyDeclarationSyntaxExtensions.cs +++ b/src/Atc.Rest.ApiGenerator/Extensions/PropertyDeclarationSyntaxExtensions.cs @@ -109,7 +109,7 @@ public static PropertyDeclarationSyntax AddValidationAttributeFromSchemaFormatIf OpenApiFormatTypeConstants.Email => propertyDeclaration.AddValidationAttributeEmail(schema), OpenApiFormatTypeConstants.Uri => propertyDeclaration.AddValidationAttribute(new UriAttribute()), - _ => throw new NotImplementedException($"Schema Format '{schema.Format}' must be implemented.") + _ => throw new NotImplementedException($"Schema Format '{schema.Format}' must be implemented."), }; } @@ -165,7 +165,7 @@ schema.MinLength is null && { OpenApiDataTypeConstants.Number when !schema.HasFormatType() => RangeAttributeDouble(propertyDeclaration, schema), OpenApiDataTypeConstants.Integer when schema.HasFormatType() && schema.IsFormatTypeInt64() => RangeAttributeLong(propertyDeclaration, schema), - _ => RangeAttributeInt(propertyDeclaration, schema) + _ => RangeAttributeInt(propertyDeclaration, schema), }; } diff --git a/src/Atc.Rest.ApiGenerator/Extensions/StringExtensions.cs b/src/Atc.Rest.ApiGenerator/Extensions/StringExtensions.cs index 07506edfc..7502582cc 100644 --- a/src/Atc.Rest.ApiGenerator/Extensions/StringExtensions.cs +++ b/src/Atc.Rest.ApiGenerator/Extensions/StringExtensions.cs @@ -6,16 +6,16 @@ internal static class StringExtensions { private const string AutoPropGetSetResultPattern = " { get; set; }"; private const string AutoPropGetResultPattern = " { get; }"; - private static readonly Regex AutoPropGetSetRegex = new (@"\s*\{\s*get;\s*set;\s*}"); - private static readonly Regex AutoPropGetRegex = new (@"\s*\{\s*get;\s*}"); - private static readonly Regex AutoPropInitializerGetSetRegex = new (@"\s*\{ get; set; }\s*= \s*"); - private static readonly Regex AutoPropInitializerGetRegex = new (@"\s*\{ get; }\s*= \s*"); - private static readonly Regex AutoPublicLinesRegex = new (@"\s*;\s*public \s*"); - private static readonly Regex AutoPrivateLinesRegex = new (@"\s*;\s*private \s*"); - private static readonly Regex AutoCommentLinesRegex = new (@"\s*;\s*/// \s*"); - private static readonly Regex AutoBracketSpacingStartRegex = new (@"(\S)({)(\S)"); - private static readonly Regex AutoBracketSpacingEndRegex = new (@"(\S)(})(\S)"); - private static readonly Regex ConstructorWithInheritResultRegex = new (@":\s*base\(result\)\s*\{\s*\}"); + private static readonly Regex AutoPropGetSetRegex = new(@"\s*\{\s*get;\s*set;\s*}"); + private static readonly Regex AutoPropGetRegex = new(@"\s*\{\s*get;\s*}"); + private static readonly Regex AutoPropInitializerGetSetRegex = new(@"\s*\{ get; set; }\s*= \s*"); + private static readonly Regex AutoPropInitializerGetRegex = new(@"\s*\{ get; }\s*= \s*"); + private static readonly Regex AutoPublicLinesRegex = new(@"\s*;\s*public \s*"); + private static readonly Regex AutoPrivateLinesRegex = new(@"\s*;\s*private \s*"); + private static readonly Regex AutoCommentLinesRegex = new(@"\s*;\s*/// \s*"); + private static readonly Regex AutoBracketSpacingStartRegex = new(@"(\S)({)(\S)"); + private static readonly Regex AutoBracketSpacingEndRegex = new(@"(\S)(})(\S)"); + private static readonly Regex ConstructorWithInheritResultRegex = new(@":\s*base\(result\)\s*\{\s*\}"); private static readonly string[] LineBreaks = { "\r\n", "\r", "\n" }; diff --git a/src/Atc.Rest.ApiGenerator/Factories/SuppressMessageAttributeFactory.cs b/src/Atc.Rest.ApiGenerator/Factories/SuppressMessageAttributeFactory.cs index e2583e5a2..17411234d 100644 --- a/src/Atc.Rest.ApiGenerator/Factories/SuppressMessageAttributeFactory.cs +++ b/src/Atc.Rest.ApiGenerator/Factories/SuppressMessageAttributeFactory.cs @@ -23,7 +23,7 @@ public static SuppressMessageAttribute Create( { // TODO: Add all rules 1062 => new SuppressMessageAttribute("Design", "CA1062:Validate arguments of public methods") { Justification = justification }, - _ => throw new NotImplementedException($"Rule for CA{checkId} must be implemented.") + _ => throw new NotImplementedException($"Rule for CA{checkId} must be implemented."), }; } } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator/Helpers/AtcApiNugetClientHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/AtcApiNugetClientHelper.cs index 3568a8495..e758db3e6 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/AtcApiNugetClientHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/AtcApiNugetClientHelper.cs @@ -3,7 +3,7 @@ namespace Atc.Rest.ApiGenerator.Helpers; public static class AtcApiNugetClientHelper { private const string BaseAddress = "https://atc-api.azurewebsites.net/nuget-search"; - private static readonly ConcurrentDictionary<string, Version> Cache = new (StringComparer.Ordinal); + private static readonly ConcurrentDictionary<string, Version> Cache = new(StringComparer.Ordinal); [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "OK.")] public static Version? GetLatestVersionForPackageId( diff --git a/src/Atc.Rest.ApiGenerator/Helpers/GenerateCodeHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/GenerateCodeHelper.cs index 8bc04357c..ac4db681d 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/GenerateCodeHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/GenerateCodeHelper.cs @@ -30,6 +30,6 @@ internal static string GetTrailingChar( TrailingCharType.Comma => ",", TrailingCharType.SemiColon => ";", TrailingCharType.Colon => ":", - _ => throw new ArgumentOutOfRangeException(nameof(trailingChar), trailingChar, null) + _ => throw new ArgumentOutOfRangeException(nameof(trailingChar), trailingChar, null), }; } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator/Helpers/GenerateHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/GenerateHelper.cs index 98417d7a0..0f23227bc 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/GenerateHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/GenerateHelper.cs @@ -6,7 +6,7 @@ namespace Atc.Rest.ApiGenerator.Helpers; public static class GenerateHelper { - private static readonly Version AtcToolVersion = new (1, 1, 405, 0); // TODO: Fix version + private static readonly Version AtcToolVersion = new(1, 1, 405, 0); // TODO: Fix version public static Version GetAtcVersion() { diff --git a/src/Atc.Rest.ApiGenerator/Helpers/HttpClientHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/HttpClientHelper.cs index 9806d492d..b59180423 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/HttpClientHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/HttpClientHelper.cs @@ -1,10 +1,8 @@ -using System.Diagnostics; - namespace Atc.Rest.ApiGenerator.Helpers; public static class HttpClientHelper { - private static readonly ConcurrentDictionary<string, string> Cache = new (StringComparer.Ordinal); + private static readonly ConcurrentDictionary<string, string> Cache = new(StringComparer.Ordinal); public static string GetAsString( ILogger logger, diff --git a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentHelper.cs index 880594820..2a962254c 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/OpenApiDocumentHelper.cs @@ -61,7 +61,7 @@ public static Tuple<OpenApiDocument, OpenApiDiagnostic, FileInfo> CombineAndGetA { 0 => throw new IOException("Api specification file don't exist in folder."), 1 => new FileInfo(docFiles.First()), - _ => CreateCombineApiDocumentFile(specificationPath) + _ => CreateCombineApiDocumentFile(specificationPath), }; } diff --git a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateServerApiXunitTestEndpointTestHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateServerApiXunitTestEndpointTestHelper.cs index c496242d7..3b3ef32fa 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateServerApiXunitTestEndpointTestHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateServerApiXunitTestEndpointTestHelper.cs @@ -897,7 +897,7 @@ private static string PropertyValueGenerator( "Uri" => ValueTypeTestPropertiesHelper.CreateValueUri(useForBadRequest), "Email" => ValueTypeTestPropertiesHelper.CreateValueEmail(useForBadRequest), "Array" when parameter.In == ParameterLocation.Query => ValueTypeTestPropertiesHelper.CreateValueArray(parameter.Name, parameter.Schema.Items, parameter.In, useForBadRequest, 3), - _ => PropertyValueGeneratorTypeResolver(parameter, componentsSchemas, useForBadRequest) + _ => PropertyValueGeneratorTypeResolver(parameter, componentsSchemas, useForBadRequest), }; } diff --git a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateXunitTestPartsHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateXunitTestPartsHelper.cs index ae78577c0..5e41a0d87 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateXunitTestPartsHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/GenerateXunitTestPartsHelper.cs @@ -470,7 +470,7 @@ public static string PropertyValueGenerator( "Guid" => ValueTypeTestPropertiesHelper.CreateValueGuid(useForBadRequest, itemNumber), "Uri" => ValueTypeTestPropertiesHelper.CreateValueUri(useForBadRequest), "Email" => ValueTypeTestPropertiesHelper.CreateValueEmail(useForBadRequest), - _ => PropertyValueGeneratorTypeResolver(schema, componentsSchemas, useForBadRequest) + _ => PropertyValueGeneratorTypeResolver(schema, componentsSchemas, useForBadRequest), }; } diff --git a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/ValueTypeTestPropertiesHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/ValueTypeTestPropertiesHelper.cs index ab1006341..41f52db99 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/ValueTypeTestPropertiesHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/XunitTest/ValueTypeTestPropertiesHelper.cs @@ -43,7 +43,7 @@ public static string Number( { OpenApiDataTypeConstants.Number when !schema.HasFormatType() => CreateNumberDouble(schema), OpenApiDataTypeConstants.Integer when schema.HasFormatType() && schema.IsFormatTypeInt64() => CreateNumberLong(schema), - _ => CreateNumberInt(schema) + _ => CreateNumberInt(schema), }; } @@ -335,6 +335,6 @@ private static string CreateValueArrayItem( "Guid" => CreateValueGuid(useForBadRequest, itemNumber), "Uri" => CreateValueUri(useForBadRequest), "Email" => CreateValueEmail(useForBadRequest, itemNumber), - _ => throw new NotSupportedException($"PropertyValueGenerator: {name} - array of ({itemSchema.GetDataType()})") + _ => throw new NotSupportedException($"PropertyValueGenerator: {name} - array of ({itemSchema.GetDataType()})"), }; } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptions.cs b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptions.cs index d5f2e6768..da53307ce 100644 --- a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptions.cs +++ b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptions.cs @@ -2,7 +2,7 @@ namespace Atc.Rest.ApiGenerator.Models.Options; public class ApiOptions { - public ApiOptionsGenerator Generator { get; set; } = new (); + public ApiOptionsGenerator Generator { get; set; } = new(); - public ApiOptionsValidation Validation { get; set; } = new (); + public ApiOptionsValidation Validation { get; set; } = new(); } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsGenerator.cs b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsGenerator.cs index 217f1e5b7..b3c6c4f8e 100644 --- a/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsGenerator.cs +++ b/src/Atc.Rest.ApiGenerator/Models/Options/ApiOptionsGenerator.cs @@ -8,7 +8,7 @@ public class ApiOptionsGenerator public bool UseRestExtended { get; set; } = true; - public ApiOptionsGeneratorRequest Request { get; set; } = new (); + public ApiOptionsGeneratorRequest Request { get; set; } = new(); - public ApiOptionsGeneratorResponse Response { get; set; } = new (); + public ApiOptionsGeneratorResponse Response { get; set; } = new(); } \ No newline at end of file diff --git a/src/Atc.Rest.ApiGenerator/ProjectSyntaxFactories/SyntaxDocumentationFactory.cs b/src/Atc.Rest.ApiGenerator/ProjectSyntaxFactories/SyntaxDocumentationFactory.cs index f32027a77..5cc83ed70 100644 --- a/src/Atc.Rest.ApiGenerator/ProjectSyntaxFactories/SyntaxDocumentationFactory.cs +++ b/src/Atc.Rest.ApiGenerator/ProjectSyntaxFactories/SyntaxDocumentationFactory.cs @@ -437,7 +437,7 @@ private static IEnumerable<SyntaxTrivia> CreateRemarks( CreateComment("Url validation being enforced."), CreateComment("</remarks>"), }, - _ => SyntaxFactory.TriviaList() + _ => SyntaxFactory.TriviaList(), }; private static bool ShouldGenerateDefaultSummary( diff --git a/src/Atc.Rest.ApiGenerator/SyntaxFactories/SyntaxPropertyDeclarationFactory.cs b/src/Atc.Rest.ApiGenerator/SyntaxFactories/SyntaxPropertyDeclarationFactory.cs index 0da12aae8..a974e1ad8 100644 --- a/src/Atc.Rest.ApiGenerator/SyntaxFactories/SyntaxPropertyDeclarationFactory.cs +++ b/src/Atc.Rest.ApiGenerator/SyntaxFactories/SyntaxPropertyDeclarationFactory.cs @@ -144,7 +144,7 @@ public static PropertyDeclarationSyntax CreateAuto( ParameterLocation.Header => propertyDeclaration.AddFromHeaderAttribute(parameter.Name, parameter.Schema), ParameterLocation.Path => propertyDeclaration.AddFromRouteAttribute(parameter.Name, parameter.Schema), ParameterLocation.Query => propertyDeclaration.AddFromQueryAttribute(parameter.Name, parameter.Schema), - _ => throw new NotImplementedException("ParameterLocation: " + nameof(ParameterLocation) + " " + parameter.In) + _ => throw new NotImplementedException("ParameterLocation: " + nameof(ParameterLocation) + " " + parameter.In), }; } diff --git a/src/Atc.Rest.ApiGenerator/SyntaxGenerators/ApiClient/SyntaxGeneratorClientEndpoint.cs b/src/Atc.Rest.ApiGenerator/SyntaxGenerators/ApiClient/SyntaxGeneratorClientEndpoint.cs index 3d5eefa06..1bb9d5704 100644 --- a/src/Atc.Rest.ApiGenerator/SyntaxGenerators/ApiClient/SyntaxGeneratorClientEndpoint.cs +++ b/src/Atc.Rest.ApiGenerator/SyntaxGenerators/ApiClient/SyntaxGeneratorClientEndpoint.cs @@ -369,7 +369,7 @@ private StatementSyntax CreateExpressionStatementForWithMethodParameterMap( ParameterLocation.Query => nameof(IMessageRequestBuilder.WithQueryParameter), ParameterLocation.Header => nameof(IMessageRequestBuilder.WithHeaderParameter), ParameterLocation.Path => nameof(IMessageRequestBuilder.WithPathParameter), - _ => throw new NotSupportedException(nameof(parameter.In)) + _ => throw new NotSupportedException(nameof(parameter.In)), }; var parameterMapName = parameter.Name; diff --git a/src/Atc.Rest.ApiGenerator/SyntaxGenerators/Domain/SyntaxGeneratorHandler.cs b/src/Atc.Rest.ApiGenerator/SyntaxGenerators/Domain/SyntaxGeneratorHandler.cs index a261220fc..32d598d8b 100644 --- a/src/Atc.Rest.ApiGenerator/SyntaxGenerators/Domain/SyntaxGeneratorHandler.cs +++ b/src/Atc.Rest.ApiGenerator/SyntaxGenerators/Domain/SyntaxGeneratorHandler.cs @@ -210,7 +210,8 @@ private MemberDeclarationSyntax CreateInvokeExecuteAsyncMethod( SyntaxFactory.Token( CreatePragmaWarningCodeStyle1998(true), SyntaxKind.PrivateKeyword, - SyntaxFactory.TriviaList()), SyntaxFactory.Token(SyntaxKind.AsyncKeyword))) + SyntaxFactory.TriviaList()), + SyntaxFactory.Token(SyntaxKind.AsyncKeyword))) .WithParameterList(SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList<ParameterSyntax>(arguments))) .WithBody( SyntaxFactory.Block(SyntaxThrowStatementFactory.CreateNotImplementedException()) diff --git a/test/Atc.Rest.ApiGenerator.Tests/CodeComplianceTests.cs b/test/Atc.Rest.ApiGenerator.Tests/CodeComplianceTests.cs index 531ac17eb..1dd20e31d 100644 --- a/test/Atc.Rest.ApiGenerator.Tests/CodeComplianceTests.cs +++ b/test/Atc.Rest.ApiGenerator.Tests/CodeComplianceTests.cs @@ -9,7 +9,7 @@ public class CodeComplianceTests private readonly Assembly sourceAssembly = typeof(AtcRestApiGeneratorAssemblyTypeInitializer).Assembly; private readonly Assembly testAssembly = typeof(CodeComplianceTests).Assembly; - private readonly List<Type> excludeTypes = new () + private readonly List<Type> excludeTypes = new() { // TODO: Add UnitTest and remove from this list!! typeof(AtcApiNugetClientHelper), diff --git a/test/Atc.Rest.ApiGenerator.Tests/CodeDocumentationTests.cs b/test/Atc.Rest.ApiGenerator.Tests/CodeDocumentationTests.cs index 344944abb..ec650bab3 100644 --- a/test/Atc.Rest.ApiGenerator.Tests/CodeDocumentationTests.cs +++ b/test/Atc.Rest.ApiGenerator.Tests/CodeDocumentationTests.cs @@ -24,7 +24,8 @@ public void RunMarkdownCodeDocGenerator() var codeDocPath = Path.Combine( Path.Combine( - Path.Combine(rootDirectory!.FullName, "docs"), "CodeDoc"), sourceAssembly.GetName().Name!); + Path.Combine(rootDirectory!.FullName, "docs"), "CodeDoc"), + sourceAssembly.GetName().Name!); var codeDocDirectory = new DirectoryInfo(codeDocPath); if (!codeDocDirectory.Exists) { From 8965a48515c91a2eb0720ec82550feb7fbb1b131 Mon Sep 17 00:00:00 2001 From: Kim Lund Johansen <johansen@kimlund.com> Date: Thu, 25 Aug 2022 15:58:05 +0200 Subject: [PATCH 7/7] fix: Coding rule warnings. --- .../Helpers/NugetPackageReferenceHelper.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs b/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs index 3d4fe76b7..31f4ebf37 100644 --- a/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs +++ b/src/Atc.Rest.ApiGenerator/Helpers/NugetPackageReferenceHelper.cs @@ -9,8 +9,8 @@ public static class NugetPackageReferenceHelper var packageReference = new List<Tuple<string, string, string?>> { - new ("Atc", atcVersion, null), - new ("Atc.Rest", atcVersion, null), + new("Atc", atcVersion, null), + new("Atc.Rest", atcVersion, null), }; if (useRestExtended) @@ -33,8 +33,8 @@ public static class NugetPackageReferenceHelper var packageReference = new List<Tuple<string, string, string?>> { - new ("Atc", atcVersion, null), - new ("Atc.Rest", atcVersion, null), + new("Atc", atcVersion, null), + new("Atc.Rest", atcVersion, null), }; return packageReference; @@ -46,8 +46,8 @@ public static class NugetPackageReferenceHelper var packageReference = new List<Tuple<string, string, string?>> { - new ("Atc", atcVersion, null), - new ("Atc.Rest.Client", "1.0.36", null), + new("Atc", atcVersion, null), + new("Atc.Rest.Client", "1.0.36", null), }; return packageReference; @@ -57,11 +57,11 @@ public static class NugetPackageReferenceHelper { var packageReference = new List<Tuple<string, string, string?>> { - new ("Atc.XUnit", "2.0.93", null), - new ("AutoFixture", "4.17.0", null), - new ("AutoFixture.AutoNSubstitute", "4.17.0", null), - new ("AutoFixture.Xunit2", "4.17.0", null), - new ("FluentAssertions", "6.5.1", null), + new("Atc.XUnit", "2.0.93", null), + new("AutoFixture", "4.17.0", null), + new("AutoFixture.AutoNSubstitute", "4.17.0", null), + new("AutoFixture.Xunit2", "4.17.0", null), + new("FluentAssertions", "6.5.1", null), }; if (useMvc) @@ -71,10 +71,10 @@ public static class NugetPackageReferenceHelper packageReference.AddRange(new List<Tuple<string, string, string?>> { - new ("Microsoft.NET.Test.Sdk", "17.1.0", null), - new ("NSubstitute", "4.3.0", null), - new ("xunit", "2.4.1", null), - new ("xunit.runner.visualstudio", "2.4.3", "<PrivateAssets>all</PrivateAssets>\n<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>"), + new("Microsoft.NET.Test.Sdk", "17.1.0", null), + new("NSubstitute", "4.3.0", null), + new("xunit", "2.4.1", null), + new("xunit.runner.visualstudio", "2.4.3", "<PrivateAssets>all</PrivateAssets>\n<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>"), }); return packageReference;