From 2819ce5e2e1000e4745c77483fa4b183cbb5008a Mon Sep 17 00:00:00 2001 From: Havunen Date: Sun, 18 Feb 2024 14:59:21 +0200 Subject: [PATCH] Define StringComparer for all Dictionaries of string key type --- .gitignore | 3 +- .../DotSwashbuckleGenerator.cs | 4 +- .../OpenApiGenerateJsonBenchmark.cs | 4 +- .../Program.cs | 4 +- .../ApiTestRunnerOptions.cs | 3 +- .../CommandRunner.cs | 6 +-- .../ReDocMiddleware.cs | 5 +- .../ReDocOptions.cs | 2 +- .../ISwaggerProvider.cs | 6 +++ .../SchemaGenerator/SchemaGenerator.cs | 2 +- .../SwaggerGenerator/SchemaRepository.cs | 2 +- .../SwaggerGenerator/SwaggerGenerator.cs | 4 +- .../SwaggerGeneratorOptions.cs | 4 +- .../SwaggerUIMiddleware.cs | 3 +- .../SwaggerUIOptions.cs | 2 +- .../JsonValidatorTests.cs | 5 +- .../RequestValidatorTests.cs | 8 +-- .../ResponseValidatorTests.cs | 15 +++--- .../NewtonsoftSchemaGeneratorTests.cs | 2 +- .../SwaggerGenerator/SwaggerGeneratorTests.cs | 54 +++++++++---------- .../XmlCommentsRequestBodyFilterTests.cs | 9 ++-- .../ApiExplorer/ApiDescriptionFactory.cs | 2 +- test/WebSites/OAuth2Integration/Startup.cs | 2 +- .../CreateUserTests.cs | 6 +-- 24 files changed, 85 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index 6eed564936..0675f1fb88 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ Thumbs.db test/WebSites/CliExample/wwwroot/api-docs/v1/*.json test/WebSites/CliExampleWithFactory/wwwroot/api-docs/v1/*.json test/WebSites/NswagClientExample/NSwagClient/ -*ncrunch* \ No newline at end of file +*ncrunch* +BenchmarkDotNet.Artifacts \ No newline at end of file diff --git a/benches/DotSwashbuckle.AspNetCore.Benchmark.Logic/DotSwashbuckleGenerator.cs b/benches/DotSwashbuckle.AspNetCore.Benchmark.Logic/DotSwashbuckleGenerator.cs index 1a47cef0ab..7ae2c74f08 100644 --- a/benches/DotSwashbuckle.AspNetCore.Benchmark.Logic/DotSwashbuckleGenerator.cs +++ b/benches/DotSwashbuckle.AspNetCore.Benchmark.Logic/DotSwashbuckleGenerator.cs @@ -8,11 +8,11 @@ namespace DotSwashbuckle.AspNetCore.Benchmark.Logic public class DotSwashbuckleGenerator { - public static string CreateSwaggerDoc(IServiceProvider serviceProvider, bool isYaml, bool isV2) + public static async Task CreateSwaggerDoc(IServiceProvider serviceProvider, bool isYaml, bool isV2) { // 3) Retrieve Swagger via configured provider var swaggerProvider = serviceProvider.GetRequiredService(); - var swagger = swaggerProvider.GetSwagger( + var swagger = await swaggerProvider.GetSwaggerAsync( "v1", null, null diff --git a/benches/DotSwashbuckle.AspNetCore.Benchmark/OpenApiGenerateJsonBenchmark.cs b/benches/DotSwashbuckle.AspNetCore.Benchmark/OpenApiGenerateJsonBenchmark.cs index bd509e9487..d872ab1ae1 100644 --- a/benches/DotSwashbuckle.AspNetCore.Benchmark/OpenApiGenerateJsonBenchmark.cs +++ b/benches/DotSwashbuckle.AspNetCore.Benchmark/OpenApiGenerateJsonBenchmark.cs @@ -24,9 +24,9 @@ public void GlobalSetup() } [Benchmark] - public string DotSwashbuckleOpenApiV2() + public async Task DotSwashbuckleOpenApiV2() { - return DotSwashbuckleGenerator.CreateSwaggerDoc( + return await DotSwashbuckleGenerator.CreateSwaggerDoc( assemblyProviders["Basic.dll"], false, true diff --git a/benches/DotSwashbuckle.AspNetCore.Console/Program.cs b/benches/DotSwashbuckle.AspNetCore.Console/Program.cs index 2462af026c..eae7ced022 100644 --- a/benches/DotSwashbuckle.AspNetCore.Console/Program.cs +++ b/benches/DotSwashbuckle.AspNetCore.Console/Program.cs @@ -5,7 +5,7 @@ namespace DotSwashbuckle.AspNetCore.Console; public class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { var serviceProvider = AssemblyServiceProvider.GetServiceProvider( AssemblyLoadContext.Default.LoadFromAssemblyPath( @@ -15,7 +15,7 @@ public static void Main(string[] args) for (var i = 0; i < 1000; i++) { - DotSwashbuckleGenerator.CreateSwaggerDoc( + await DotSwashbuckleGenerator.CreateSwaggerDoc( serviceProvider, false, true diff --git a/src/DotSwashbuckle.AspNetCore.ApiTesting/ApiTestRunnerOptions.cs b/src/DotSwashbuckle.AspNetCore.ApiTesting/ApiTestRunnerOptions.cs index 25cd6dfe0c..1a48121bdb 100644 --- a/src/DotSwashbuckle.AspNetCore.ApiTesting/ApiTestRunnerOptions.cs +++ b/src/DotSwashbuckle.AspNetCore.ApiTesting/ApiTestRunnerOptions.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Microsoft.OpenApi.Models; @@ -7,7 +8,7 @@ public class ApiTestRunnerOptions { public ApiTestRunnerOptions() { - OpenApiDocs = new Dictionary(); + OpenApiDocs = new Dictionary(StringComparer.Ordinal); ContentValidators = new List { new JsonContentValidator() }; GenerateOpenApiFiles = false; FileOutputRoot = null; diff --git a/src/DotSwashbuckle.AspNetCore.Cli/CommandRunner.cs b/src/DotSwashbuckle.AspNetCore.Cli/CommandRunner.cs index 0d6fc008aa..2abdfcc6f9 100644 --- a/src/DotSwashbuckle.AspNetCore.Cli/CommandRunner.cs +++ b/src/DotSwashbuckle.AspNetCore.Cli/CommandRunner.cs @@ -17,8 +17,8 @@ public CommandRunner(string commandName, string commandDescription, TextWriter o { CommandName = commandName; CommandDescription = commandDescription; - _argumentDescriptors = new Dictionary(); - _optionDescriptors = new Dictionary(); + _argumentDescriptors = new Dictionary(StringComparer.Ordinal); + _optionDescriptors = new Dictionary(StringComparer.Ordinal); _runFunc = (namedArgs) => { return 1; }; // noop _subRunners = new List(); _output = output; @@ -70,7 +70,7 @@ public int Run(IEnumerable args) private bool TryParseArgs(IEnumerable args, out IDictionary namedArgs) { - namedArgs = new Dictionary(); + namedArgs = new Dictionary(StringComparer.Ordinal); var argsQueue = new Queue(args); // Process options first diff --git a/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs b/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs index ccb36c8455..7ae0bac6d8 100644 --- a/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs +++ b/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; @@ -108,7 +109,7 @@ private async Task RespondWithIndexHtml(HttpResponse response) private IDictionary GetIndexArguments() { - return new Dictionary() + return new Dictionary(StringComparer.Ordinal) { { "%(DocumentTitle)", _options.DocumentTitle }, { "%(HeadContent)", _options.HeadContent }, diff --git a/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocOptions.cs b/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocOptions.cs index efe07cc281..5e6e0858bf 100644 --- a/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocOptions.cs +++ b/src/DotSwashbuckle.AspNetCore.ReDoc/ReDocOptions.cs @@ -109,6 +109,6 @@ public class ConfigObject public bool SortPropsAlphabetically { get; set; } = false; [JsonExtensionData] - public Dictionary AdditionalItems { get; set; } = new Dictionary(); + public Dictionary AdditionalItems { get; set; } = new Dictionary(StringComparer.Ordinal); } } \ No newline at end of file diff --git a/src/DotSwashbuckle.AspNetCore.Swagger/ISwaggerProvider.cs b/src/DotSwashbuckle.AspNetCore.Swagger/ISwaggerProvider.cs index c743319a0a..cbae2a7c57 100644 --- a/src/DotSwashbuckle.AspNetCore.Swagger/ISwaggerProvider.cs +++ b/src/DotSwashbuckle.AspNetCore.Swagger/ISwaggerProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.OpenApi.Models; namespace DotSwashbuckle.AspNetCore.Swagger @@ -11,6 +12,11 @@ OpenApiDocument GetSwagger( string documentName, string host = null, string basePath = null); + + Task GetSwaggerAsync( + string documentName, + string host = null, + string basePath = null); } public class UnknownSwaggerDocument : InvalidOperationException diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs index 9862463146..4275ad70ae 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs @@ -345,7 +345,7 @@ private OpenApiSchema CreateObjectSchema(DataContract dataContract, SchemaReposi var schema = new OpenApiSchema { Type = "object", - Properties = new Dictionary(), + Properties = new Dictionary(StringComparer.Ordinal), Required = new SortedSet(), AdditionalPropertiesAllowed = false }; diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SchemaRepository.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SchemaRepository.cs index 1a06785a60..35a8da9a8b 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SchemaRepository.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SchemaRepository.cs @@ -16,7 +16,7 @@ public SchemaRepository(string documentName = null) public string DocumentName { get; } - public Dictionary Schemas { get; private set; } = new Dictionary(); + public Dictionary Schemas { get; private set; } = new Dictionary(StringComparer.Ordinal); public void RegisterType(Type type, string schemaId) { diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs index f1c860f17e..7f82889b58 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs @@ -504,7 +504,7 @@ private OpenApiSchema GenerateSchemaFromFormParameters( IEnumerable formParameters, SchemaRepository schemaRepository) { - var properties = new Dictionary(); + var properties = new Dictionary(StringComparer.Ordinal); var requiredPropertyNames = new List(); foreach (var formParameter in formParameters) @@ -601,7 +601,7 @@ private OpenApiMediaType CreateResponseMediaType(ModelMetadata modelMetadata, Sc }; } - private static readonly Dictionary OperationTypeMap = new Dictionary + private static readonly Dictionary OperationTypeMap = new Dictionary(StringComparer.Ordinal) { { "GET", OperationType.Get }, { "PUT", OperationType.Put }, diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGeneratorOptions.cs b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGeneratorOptions.cs index acf43177f5..3804892987 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGeneratorOptions.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGeneratorOptions.cs @@ -13,7 +13,7 @@ public class SwaggerGeneratorOptions { public SwaggerGeneratorOptions() { - SwaggerDocs = new Dictionary(); + SwaggerDocs = new Dictionary(StringComparer.Ordinal); DocInclusionPredicate = DefaultDocInclusionPredicate; OperationIdSelector = DefaultOperationIdSelector; TagsSelector = DefaultTagsSelector; @@ -21,7 +21,7 @@ public SwaggerGeneratorOptions() SecuritySchemesSelector = null; SchemaComparer = StringComparer.Ordinal; Servers = new List(); - SecuritySchemes = new Dictionary(); + SecuritySchemes = new Dictionary(StringComparer.Ordinal); SecurityRequirements = new List(); ParameterFilters = new List(); RequestBodyFilters = new List(); diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs b/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs index d219e51f29..e00f1e9b4f 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs @@ -14,6 +14,7 @@ using Microsoft.Extensions.FileProviders; using Microsoft.AspNetCore.StaticFiles; using System.Linq; +using System; namespace DotSwashbuckle.AspNetCore.SwaggerUI { @@ -110,7 +111,7 @@ private async Task RespondWithIndexHtml(HttpResponse response) private IDictionary GetIndexArguments() { - return new Dictionary() + return new Dictionary(StringComparer.Ordinal) { { "%(DocumentTitle)", _options.DocumentTitle }, { "%(HeadContent)", _options.HeadContent }, diff --git a/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs b/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs index 9b42a90a65..e8589a4230 100644 --- a/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs +++ b/src/DotSwashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs @@ -142,7 +142,7 @@ public class ConfigObject public string ValidatorUrl { get; set; } = null; [JsonExtensionData] - public Dictionary AdditionalItems { get; set; } = new Dictionary(); + public Dictionary AdditionalItems { get; set; } = new Dictionary(StringComparer.Ordinal); } public class UrlDescriptor diff --git a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/JsonValidatorTests.cs b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/JsonValidatorTests.cs index 0aacd35143..37e3dbd47f 100644 --- a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/JsonValidatorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/JsonValidatorTests.cs @@ -3,6 +3,7 @@ using Microsoft.OpenApi.Models; using Newtonsoft.Json.Linq; using System.Linq; +using System; namespace DotSwashbuckle.AspNetCore.ApiTesting.Test { @@ -433,7 +434,7 @@ public void Validate_ReturnsError_IfKnownPropertyDoesNotMatchPropertySchema( var openApiSchema = new OpenApiSchema { Type = "object", - Properties = new Dictionary + Properties = new Dictionary(StringComparer.Ordinal) { [ "id" ] = new OpenApiSchema { Type = propertySchemaType } } @@ -606,7 +607,7 @@ public void Validate_SupportsReferencedSchemas_IfDefinedInProvidedOpenApiDocumen { Components = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new Dictionary(StringComparer.Ordinal) { ["ref"] = new OpenApiSchema { Type = "number" } } diff --git a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs index 3b8d43f908..62e0095508 100644 --- a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/RequestValidatorTests.cs @@ -262,7 +262,7 @@ public void Validate_ThrowsException_IfRequiredContentIsNotPresent( RequestBody = new OpenApiRequestBody { Required = true, - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { [ "text/plain" ] = new OpenApiMediaType() } @@ -294,7 +294,7 @@ public void Validate_ThrowsException_IfContentMediaTypeIsNotSpecified( { RequestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { [ "application/json" ] = new OpenApiMediaType() } @@ -326,7 +326,7 @@ public void Validate_DelegatesContentValidationToInjectedContentValidators( { RequestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { [ "application/json" ] = new OpenApiMediaType { @@ -370,7 +370,7 @@ private OpenApiDocument DocumentWithOperation(string pathTemplate, OperationType }, Components = new OpenApiComponents { - Schemas = new Dictionary() + Schemas = new Dictionary(StringComparer.Ordinal) } }; } diff --git a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs index 2c25c2f11c..fc3c8f7de2 100644 --- a/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.ApiTesting.Test/ResponseValidatorTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Text; @@ -50,7 +51,7 @@ public void Validate_ThrowsException_IfRequiredHeaderIsNotPresent( { [ "201" ] = new OpenApiResponse { - Headers = new Dictionary + Headers = new Dictionary(StringComparer.Ordinal) { [ "test-header" ] = new OpenApiHeader { @@ -94,7 +95,7 @@ public void Validate_ThrowsException_IfHeaderIsNotOfSpecifiedType( { [ "201" ] = new OpenApiResponse { - Headers = new Dictionary + Headers = new Dictionary(StringComparer.Ordinal) { [ "test-header" ] = new OpenApiHeader { @@ -135,7 +136,7 @@ public void Validate_ThrowsException_IfExpectedContentIsNotPresent( { [ "200" ] = new OpenApiResponse { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["text/plain"] = new OpenApiMediaType() } @@ -168,7 +169,7 @@ public void Validate_ThrowsException_IfContentMediaTypeIsNotSpecified( { [ "200" ] = new OpenApiResponse { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType() } @@ -201,7 +202,7 @@ public void Validate_DelegatesContentValidationToInjectedContentValidators( { [ "200" ] = new OpenApiResponse { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType { @@ -245,7 +246,7 @@ private OpenApiDocument DocumentWithOperation(string pathTemplate, OperationType }, Components = new OpenApiComponents { - Schemas = new Dictionary() + Schemas = new Dictionary(StringComparer.Ordinal) } }; } diff --git a/test/DotSwashbuckle.AspNetCore.Newtonsoft.Test/SchemaGenerator/NewtonsoftSchemaGeneratorTests.cs b/test/DotSwashbuckle.AspNetCore.Newtonsoft.Test/SchemaGenerator/NewtonsoftSchemaGeneratorTests.cs index 7102e56816..ff20da200d 100644 --- a/test/DotSwashbuckle.AspNetCore.Newtonsoft.Test/SchemaGenerator/NewtonsoftSchemaGeneratorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.Newtonsoft.Test/SchemaGenerator/NewtonsoftSchemaGeneratorTests.cs @@ -651,7 +651,7 @@ public void GenerateSchema_HonorsSerializerSetting_TypeNameHandling( Assert.NotNull(schema.Discriminator); Assert.Equal("$type", schema.Discriminator.PropertyName); Assert.Equal( - expected: new Dictionary + expected: new Dictionary(StringComparer.Ordinal) { [string.Format(expectedDiscriminatorMappingKeyFormat, "BaseType")] = "#/components/schemas/BaseType", [string.Format(expectedDiscriminatorMappingKeyFormat, "SubType1")] = "#/components/schemas/SubType1", diff --git a/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenerator/SwaggerGeneratorTests.cs b/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenerator/SwaggerGeneratorTests.cs index 9b28bda73e..1b6bc67533 100644 --- a/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenerator/SwaggerGeneratorTests.cs +++ b/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/SwaggerGenerator/SwaggerGeneratorTests.cs @@ -36,7 +36,7 @@ public void GetSwagger_GeneratesSwaggerDocument_ForApiDescriptionsWithMatchingGr }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } } @@ -72,7 +72,7 @@ public void GetSwagger_GeneratesSwaggerDocument_ForApiDescriptionsWithConstraine }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } } @@ -126,7 +126,7 @@ public void GetSwagger_SetsOperationIdToEndpointName_IfActionHasEndpointNameMeta var actionDescriptor = new ActionDescriptor { EndpointMetadata = new List() { new EndpointNameMetadata("SomeEndpointName") }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -163,7 +163,7 @@ public void GetSwagger_UseProvidedOpenApiOperation_IfExistsInMetadata() } } }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -196,7 +196,7 @@ public void GetSwagger_GenerateProducesSchemas_ForProvidedOpenApiOperation() { ["200"] = new() { - Content = new Dictionary() + Content = new Dictionary(StringComparer.Ordinal) { ["application/someMediaType"] = new() } @@ -204,7 +204,7 @@ public void GetSwagger_GenerateProducesSchemas_ForProvidedOpenApiOperation() } } }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -252,14 +252,14 @@ public void GetSwagger_GenerateConsumesSchemas_ForProvidedOpenApiOperation() OperationId = "OperationIdSetInMetadata", RequestBody = new() { - Content = new Dictionary() + Content = new Dictionary(StringComparer.Ordinal) { ["application/someMediaType"] = new() } } } }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -315,7 +315,7 @@ public void GetSwagger_GenerateParametersSchemas_ForProvidedOpenApiOperation() } } }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -355,7 +355,7 @@ public void GetSwagger_SetsOperationIdToNull_IfActionHasNoEndpointMetadata() var actionDescriptor = new ActionDescriptor { EndpointMetadata = null, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -524,7 +524,7 @@ void Execute(object obj) { } var actionDescriptor = new ActionDescriptor { - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = "Foo", } @@ -872,7 +872,7 @@ public void GetSwagger_SupportsOption_IgnoreObsoleteActions() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -903,7 +903,7 @@ public void GetSwagger_SupportsOption_SortKeySelector() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -927,7 +927,7 @@ public void GetSwagger_SupportsOption_TagSelector() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -947,7 +947,7 @@ public void GetSwagger_CanReadTagsFromMetadata() var actionDescriptor = new ActionDescriptor { EndpointMetadata = new List() { new TagsAttribute("Some", "Tags", "Here") }, - RouteValues = new Dictionary + RouteValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) } @@ -978,7 +978,7 @@ public void GetSwagger_SupportsOption_ConflictingActionsResolver() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1021,7 +1021,7 @@ public void GetSwagger_SupportsOption_DescribeAllParametersInCamelCase( }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1043,7 +1043,7 @@ public void GetSwagger_SupportsOption_Servers() apiDescriptions: new ApiDescription[] { }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1067,11 +1067,11 @@ public void GetSwagger_SupportsOption_SecuritySchemes() apiDescriptions: new ApiDescription[] { }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, - SecuritySchemes = new Dictionary + SecuritySchemes = new Dictionary(StringComparer.Ordinal) { ["basic"] = new OpenApiSecurityScheme { Type = SecuritySchemeType.Http, Scheme = "basic" } } @@ -1099,7 +1099,7 @@ public async Task GetSwagger_SupportsOption_InferSecuritySchemes( }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1128,7 +1128,7 @@ public async Task GetSwagger_SupportsOption_SecuritySchemesSelector( }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1164,7 +1164,7 @@ public void GetSwagger_SupportsOption_ParameterFilters() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1201,7 +1201,7 @@ public void GetSwagger_SupportsOption_RequestBodyFilters() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1231,7 +1231,7 @@ public void GetSwagger_SupportsOption_OperationFilters() }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1257,7 +1257,7 @@ public void GetSwagger_SupportsOption_DocumentFilters() apiDescriptions: new ApiDescription[] { }, options: new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } }, @@ -1291,7 +1291,7 @@ private SwaggerGenerator Subject( private static readonly SwaggerGeneratorOptions DefaultOptions = new SwaggerGeneratorOptions { - SwaggerDocs = new Dictionary + SwaggerDocs = new Dictionary(StringComparer.Ordinal) { ["v1"] = new OpenApiInfo { Version = "V1", Title = "Test API" } } diff --git a/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs b/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs index 7619c74671..af2c170f90 100644 --- a/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs +++ b/test/DotSwashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs @@ -6,6 +6,7 @@ using Xunit; using DotSwashbuckle.AspNetCore.TestSupport; using System.Collections.Generic; +using System; namespace DotSwashbuckle.AspNetCore.SwaggerGen.Test { @@ -16,7 +17,7 @@ public void Apply_SetsDescriptionAndExample_FromActionParamTag() { var requestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "string" } } } @@ -42,7 +43,7 @@ public void Apply_SetsDescriptionAndExample_FromUnderlyingGenericTypeActionParam { var requestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "string" } } } @@ -68,7 +69,7 @@ public void Apply_SetsDescriptionAndExample_FromPropertySummaryAndExampleTags() { var requestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "string" } } } @@ -92,7 +93,7 @@ public void Apply_SetsDescriptionAndExample_FromUriTypePropertySummaryAndExample { var requestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { ["application/json"] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "string" } } } diff --git a/test/DotSwashbuckle.AspNetCore.TestSupport/ApiExplorer/ApiDescriptionFactory.cs b/test/DotSwashbuckle.AspNetCore.TestSupport/ApiExplorer/ApiDescriptionFactory.cs index dbf6c4167d..c825c73450 100644 --- a/test/DotSwashbuckle.AspNetCore.TestSupport/ApiExplorer/ApiDescriptionFactory.cs +++ b/test/DotSwashbuckle.AspNetCore.TestSupport/ApiExplorer/ApiDescriptionFactory.cs @@ -134,7 +134,7 @@ private static ActionDescriptor CreateActionDescriptor(MethodInfo methodInfo) .Select(CreateParameterDescriptor) .ToList(); - var routeValues = new Dictionary + var routeValues = new Dictionary(StringComparer.Ordinal) { ["controller"] = methodInfo.DeclaringType.Name.Replace("Controller", string.Empty) }; diff --git a/test/WebSites/OAuth2Integration/Startup.cs b/test/WebSites/OAuth2Integration/Startup.cs index b208bb8164..fd1f8d7d1f 100644 --- a/test/WebSites/OAuth2Integration/Startup.cs +++ b/test/WebSites/OAuth2Integration/Startup.cs @@ -64,7 +64,7 @@ public void ConfigureServices(IServiceCollection services) { AuthorizationUrl = new Uri("/auth-server/connect/authorize", UriKind.Relative), TokenUrl = new Uri("/auth-server/connect/token", UriKind.Relative), - Scopes = new Dictionary + Scopes = new Dictionary(StringComparer.Ordinal) { { "readAccess", "Access read operations" }, { "writeAccess", "Access write operations" } diff --git a/test/WebSites/TestFirst.IntegrationTests/CreateUserTests.cs b/test/WebSites/TestFirst.IntegrationTests/CreateUserTests.cs index 3dcfbb623f..36281fc9e4 100644 --- a/test/WebSites/TestFirst.IntegrationTests/CreateUserTests.cs +++ b/test/WebSites/TestFirst.IntegrationTests/CreateUserTests.cs @@ -24,14 +24,14 @@ public CreateUserTests( Tags = new List { new OpenApiTag { Name = "Users" } }, RequestBody = new OpenApiRequestBody { - Content = new Dictionary + Content = new Dictionary(StringComparer.Ordinal) { [ "application/json" ] = new OpenApiMediaType { Schema = new OpenApiSchema { Type = "object", - Properties = new Dictionary + Properties = new Dictionary(StringComparer.Ordinal) { [ "email" ] = new OpenApiSchema { Type = "string" }, [ "password" ] = new OpenApiSchema { Type = "string" }, @@ -47,7 +47,7 @@ public CreateUserTests( [ "201" ] = new OpenApiResponse { Description = "User created", - Headers = new Dictionary + Headers = new Dictionary(StringComparer.Ordinal) { [ "Location" ] = new OpenApiHeader {