diff --git a/README.md b/README.md index a18c00723..f903038cd 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ var document = new OpenApiDocument { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { diff --git a/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs b/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs index f4b4f77c5..368b67e8c 100644 --- a/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs +++ b/src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs @@ -13,7 +13,7 @@ internal static class OpenApiExtensibleExtensions /// A dictionary of . /// The key corresponding to the . /// A value matching the provided extensionKey. Return null when extensionKey is not found. - internal static string GetExtension(this IDictionary extensions, string extensionKey) + internal static string GetExtension(this Dictionary extensions, string extensionKey) { if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny { Node: JsonValue castValue } && castValue.TryGetValue(out var stringValue)) { diff --git a/src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs b/src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs index 3d6362084..bd05e9649 100644 --- a/src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs +++ b/src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs @@ -34,7 +34,7 @@ public static bool IsEquals(this string? target, string? searchValue, StringComp /// The target string to split by char. /// The char separator. /// An containing substrings. - public static IList SplitByChar(this string target, char separator) + public static List SplitByChar(this string target, char separator) { if (string.IsNullOrWhiteSpace(target)) { diff --git a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs index b46e0b2a6..a07888a99 100644 --- a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs +++ b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs @@ -77,7 +77,7 @@ public override void Visit(OpenApiOperation operation) // Order matters. Resolve operationId. operationId = RemoveHashSuffix(operationId); if (operationTypeExtension.IsEquals("action") || operationTypeExtension.IsEquals("function")) - operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? new List()); + operationId = RemoveKeyTypeSegment(operationId, operation.Parameters ?? []); operationId = SingularizeAndDeduplicateOperationId(operationId.SplitByChar('.')); operationId = ResolveODataCastOperationId(operationId); operationId = ResolveByRefOperationId(operationId); @@ -119,7 +119,7 @@ private static string ResolveODataCastOperationId(string operationId) return match.Success ? $"{match.Groups[1]}{match.Groups[2]}" : operationId; } - private static string SingularizeAndDeduplicateOperationId(IList operationIdSegments) + private static string SingularizeAndDeduplicateOperationId(List operationIdSegments) { var segmentsCount = operationIdSegments.Count; var lastSegmentIndex = segmentsCount - 1; @@ -145,7 +145,7 @@ private static string RemoveHashSuffix(string operationId) return s_hashSuffixRegex.Match(operationId).Value; } - private static string RemoveKeyTypeSegment(string operationId, IList parameters) + private static string RemoveKeyTypeSegment(string operationId, List parameters) { var segments = operationId.SplitByChar('.'); foreach (var parameter in parameters) @@ -159,9 +159,9 @@ private static string RemoveKeyTypeSegment(string operationId, IList parameters) + private static void ResolveFunctionParameters(List parameters) { - foreach (var parameter in parameters.OfType().Where(static p => p.Content?.Any() ?? false)) + foreach (var parameter in parameters.OfType().Where(static p => p.Content?.Count > 0)) { // Replace content with a schema object of type array // for structured or collection-valued function parameters diff --git a/src/Microsoft.OpenApi.Hidi/StatsVisitor.cs b/src/Microsoft.OpenApi.Hidi/StatsVisitor.cs index d157a6c42..0f5a9faf4 100644 --- a/src/Microsoft.OpenApi.Hidi/StatsVisitor.cs +++ b/src/Microsoft.OpenApi.Hidi/StatsVisitor.cs @@ -27,7 +27,7 @@ public override void Visit(IOpenApiSchema schema) public int HeaderCount { get; set; } - public override void Visit(IDictionary headers) + public override void Visit(Dictionary headers) { HeaderCount++; } diff --git a/src/Microsoft.OpenApi.Workbench/StatsVisitor.cs b/src/Microsoft.OpenApi.Workbench/StatsVisitor.cs index 85dc824a4..cdcdb6af9 100644 --- a/src/Microsoft.OpenApi.Workbench/StatsVisitor.cs +++ b/src/Microsoft.OpenApi.Workbench/StatsVisitor.cs @@ -27,7 +27,7 @@ public override void Visit(IOpenApiSchema schema) public int HeaderCount { get; set; } - public override void Visit(IDictionary headers) + public override void Visit(Dictionary headers) { HeaderCount++; } diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs index 01fc02020..bea3597a6 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Collections.Generic; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -32,10 +33,8 @@ public static void AddExtension(this T element, string name, IOpenApiExtensio throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name)); } - if (element.Extensions is not null) - { - element.Extensions[name] = Utils.CheckArgumentNull(any); - } + element.Extensions ??= []; + element.Extensions[name] = Utils.CheckArgumentNull(any); } } } diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs index 5276876ce..befeddaa9 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiServerExtensions.cs @@ -21,7 +21,7 @@ public static class OpenApiServerExtensions /// 1. A substitution has no valid value in both the supplied dictionary and the default /// 2. A substitution's value is not available in the enum provided /// - public static string? ReplaceServerUrlVariables(this OpenApiServer server, IDictionary? values = null) + public static string? ReplaceServerUrlVariables(this OpenApiServer server, Dictionary? values = null) { var parsedUrl = server.Url; if (server.Variables is not null && parsedUrl is not null) diff --git a/src/Microsoft.OpenApi/Interfaces/IMetadataContainer.cs b/src/Microsoft.OpenApi/Interfaces/IMetadataContainer.cs index 2ae2248de..d97635c9c 100644 --- a/src/Microsoft.OpenApi/Interfaces/IMetadataContainer.cs +++ b/src/Microsoft.OpenApi/Interfaces/IMetadataContainer.cs @@ -14,6 +14,6 @@ public interface IMetadataContainer /// /// A collection of properties associated with the current OpenAPI element. /// - IDictionary? Metadata { get; set; } + Dictionary? Metadata { get; set; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs index fabd1a177..be7796a24 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs @@ -13,6 +13,6 @@ public interface IOpenApiExtensible : IOpenApiElement /// /// Specification extensions. /// - IDictionary? Extensions { get; set; } + Dictionary? Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs index db451d843..fc3d19cfa 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs @@ -10,6 +10,6 @@ public interface IOpenApiReadOnlyExtensible /// /// Specification extensions. /// - IDictionary? Extensions { get; } + Dictionary? Extensions { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs index c6550caa6..fc580847c 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs @@ -55,11 +55,11 @@ public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// Examples of the media type. /// - public IDictionary? Examples { get; } + public Dictionary? Examples { get; } /// /// A map containing the representations for the header. /// - public IDictionary? Content { get; } + public Dictionary? Content { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs index 6fc9abeb6..8a263f59d 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiLink.cs @@ -24,7 +24,7 @@ public interface IOpenApiLink : IOpenApiDescribedElement, IOpenApiReadOnlyExtens /// /// A map representing parameters to pass to an operation as specified with operationId or identified via operationRef. /// - public IDictionary? Parameters { get; } + public Dictionary? Parameters { get; } /// /// A literal value or {expression} to use as a request body when calling the target operation. diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs index 63c3a860f..8340fb698 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs @@ -81,7 +81,7 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyE /// Furthermore, if referencing a schema which contains an example, /// the examples value SHALL override the example provided by the schema. /// - public IDictionary? Examples { get; } + public Dictionary? Examples { get; } /// /// Example of the media type. The example SHOULD match the specified schema and encoding properties @@ -102,5 +102,5 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyE /// When example or examples are provided in conjunction with the schema object, /// the example MUST follow the prescribed serialization strategy for the parameter. /// - public IDictionary? Content { get; } + public Dictionary? Content { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs index f4348154e..ca105bd76 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs @@ -14,16 +14,16 @@ public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarized /// /// Gets the definition of operations on this path. /// - public IDictionary? Operations { get; } + public Dictionary? Operations { get; } /// /// An alternative server array to service all operations in this path. /// - public IList? Servers { get; } + public List? Servers { get; } /// /// A list of parameters that are applicable for all the operations described under this path. /// These parameters can be overridden at the operation level, but cannot be removed there. /// - public IList? Parameters { get; } + public List? Parameters { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs index b9c8304df..966361bfa 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs @@ -19,7 +19,7 @@ public interface IOpenApiRequestBody : IOpenApiDescribedElement, IOpenApiReadOnl /// REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it. /// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/* /// - public IDictionary? Content { get; } + public Dictionary? Content { get; } /// /// Converts the request body to a body parameter in preparation for a v2 serialization. /// diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs index 379526e0a..0ad10c1e9 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs @@ -12,18 +12,18 @@ public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiReadOnlyEx /// /// Maps a header name to its definition. /// - public IDictionary? Headers { get; } + public Dictionary? Headers { get; } /// /// A map containing descriptions of potential response payloads. /// The key is a media type or media type range and the value describes it. /// - public IDictionary? Content { get; } + public Dictionary? Content { get; } /// /// A map of operations links that can be followed from the response. /// The key of the map is a short name for the link, /// following the naming constraints of the names for Component Objects. /// - public IDictionary? Links { get; } + public Dictionary? Links { get; } } diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs index a960f2a5a..ea6f4edd3 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs @@ -35,7 +35,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// $vocabulary- used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. /// - public IDictionary? Vocabulary { get; } + public Dictionary? Vocabulary { get; } /// /// $dynamicRef - an applicator that allows for deferring the full resolution until runtime, at which point it is resolved each time it is encountered while evaluating an instance @@ -51,7 +51,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// $defs - reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema. /// The keyword does not directly affect the validation result /// - public IDictionary? Definitions { get; } + public Dictionary? Definitions { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -144,19 +144,19 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList? AllOf { get; } + public List? AllOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList? OneOf { get; } + public List? OneOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. /// - public IList? AnyOf { get; } + public List? AnyOf { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -167,7 +167,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public ISet? Required { get; } + public HashSet? Required { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -195,7 +195,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// Property definitions MUST be a Schema Object and not a standard JSON Schema (inline or referenced). /// - public IDictionary? Properties { get; } + public Dictionary? Properties { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -204,7 +204,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// egular expression dialect. Each property value of this object MUST be an object, and each object MUST /// be a valid Schema Object not a standard JSON Schema. /// - public IDictionary? PatternProperties { get; } + public Dictionary? PatternProperties { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -246,12 +246,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// To represent examples that cannot be naturally represented in JSON or YAML, /// a list of values can be used to contain the examples with escaping where necessary. /// - public IList? Examples { get; } + public List? Examples { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public IList? Enum { get; } + public List? Enum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -278,16 +278,16 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// This object stores any unrecognized keywords found in the schema. /// - public IDictionary? UnrecognizedKeywords { get; } + public Dictionary? UnrecognizedKeywords { get; } /// /// Any annotation to attach to the schema to be used by the application. /// Annotations are NOT (de)serialized with the schema and can be used for custom properties. /// - public IDictionary? Annotations { get; } + public Dictionary? Annotations { get; } /// /// Follow JSON Schema definition:https://json-schema.org/draft/2020-12/json-schema-validation#section-6.5.4 /// - public IDictionary>? DependentRequired { get; } + public Dictionary>? DependentRequired { get; } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 435d9155e..8bd90ed7f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -13,17 +13,16 @@ namespace Microsoft.OpenApi.Models /// /// Callback Object: A map of possible out-of band callbacks related to the parent operation. /// - public class OpenApiCallback : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiCallback + public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback { /// public Dictionary? PathItems { get; set; } - = []; /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index c3b762088..fb0129bec 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -19,60 +19,57 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible /// /// An object to hold reusable Objects. /// - public IDictionary? Schemas { get; set; } = new Dictionary(); + public Dictionary? Schemas { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Responses { get; set; } = new Dictionary(); + public Dictionary? Responses { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Parameters { get; set; } = - new Dictionary(); + public Dictionary? Parameters { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Examples { get; set; } = new Dictionary(); + public Dictionary? Examples { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? RequestBodies { get; set; } = - new Dictionary(); + public Dictionary? RequestBodies { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Headers { get; set; } = new Dictionary(); + public Dictionary? Headers { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? SecuritySchemes { get; set; } = - new Dictionary(); + public Dictionary? SecuritySchemes { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Links { get; set; } = new Dictionary(); + public Dictionary? Links { get; set; } /// /// An object to hold reusable Objects. /// - public IDictionary? Callbacks { get; set; } = new Dictionary(); + public Dictionary? Callbacks { get; set; } /// /// An object to hold reusable Object. /// - public IDictionary? PathItems { get; set; } = new Dictionary(); + public Dictionary? PathItems { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -318,7 +315,7 @@ private void RenderComponents(IOpenApiWriter writer, Action /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index 32a828c5b..8ad465241 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -21,12 +21,12 @@ public class OpenApiDiscriminator : IOpenApiSerializable, IOpenApiExtensible /// /// An object to hold mappings between payload values and schema names or references. /// - public IDictionary? Mapping { get; set; } = new Dictionary(); + public Dictionary? Mapping { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index e5f82e9cb..443123f9a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -49,7 +49,7 @@ public void RegisterComponents() /// /// An array of Server Objects, which provide connectivity information to a target server. /// - public IList? Servers { get; set; } = new List(); + public List? Servers { get; set; } = []; /// /// REQUIRED. The available paths and operations for the API. @@ -61,7 +61,7 @@ public void RegisterComponents() /// A map of requests initiated other than by an API call, for example by an out of band registration. /// The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses /// - public IDictionary? Webhooks { get; set; } = new Dictionary(); + public Dictionary? Webhooks { get; set; } /// /// An element to hold various schemas for the specification. @@ -71,14 +71,13 @@ public void RegisterComponents() /// /// A declaration of which security mechanisms can be used across the API. /// - public IList? Security { get; set; } = - new List(); + public List? Security { get; set; } private HashSet? _tags; /// /// A list of tags used by the specification with additional metadata. /// - public ISet? Tags + public HashSet? Tags { get { @@ -104,10 +103,10 @@ public ISet? Tags /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// - public IDictionary? Metadata { get; set; } + public Dictionary? Metadata { get; set; } /// /// Implements IBaseDocument @@ -133,11 +132,11 @@ public OpenApiDocument(OpenApiDocument? document) Workspace = document?.Workspace != null ? new(document.Workspace) : null; Info = document?.Info != null ? new(document.Info) : new OpenApiInfo(); JsonSchemaDialect = document?.JsonSchemaDialect ?? JsonSchemaDialect; - Servers = document?.Servers != null ? new List(document.Servers) : null; - Paths = document?.Paths != null ? new(document.Paths) : new OpenApiPaths(); + Servers = document?.Servers != null ? [.. document.Servers] : null; + Paths = document?.Paths != null ? new(document.Paths) : []; Webhooks = document?.Webhooks != null ? new Dictionary(document.Webhooks) : null; Components = document?.Components != null ? new(document?.Components) : null; - Security = document?.Security != null ? new List(document.Security) : null; + Security = document?.Security != null ? [.. document.Security] : null; Tags = document?.Tags != null ? new HashSet(document.Tags, OpenApiTagComparer.Instance) : null; ExternalDocs = document?.ExternalDocs != null ? new(document.ExternalDocs) : null; Extensions = document?.Extensions != null ? new Dictionary(document.Extensions) : null; @@ -415,10 +414,10 @@ public void SerializeAsV2(IOpenApiWriter writer) private static string? ParseServerUrl(OpenApiServer server) { - return server.ReplaceServerUrlVariables(new Dictionary(0)); + return server.ReplaceServerUrlVariables([]); } - private static void WriteHostInfoV2(IOpenApiWriter writer, IList? servers) + private static void WriteHostInfoV2(IOpenApiWriter writer, List? servers) { if (servers == null || !servers.Any()) { @@ -652,43 +651,43 @@ public bool AddComponent(string id, T componentToRegister) switch (componentToRegister) { case IOpenApiSchema openApiSchema: - Components.Schemas ??= new Dictionary(); + Components.Schemas ??= []; Components.Schemas.Add(id, openApiSchema); break; case IOpenApiParameter openApiParameter: - Components.Parameters ??= new Dictionary(); + Components.Parameters ??= []; Components.Parameters.Add(id, openApiParameter); break; case IOpenApiResponse openApiResponse: - Components.Responses ??= new Dictionary(); + Components.Responses ??= []; Components.Responses.Add(id, openApiResponse); break; case IOpenApiRequestBody openApiRequestBody: - Components.RequestBodies ??= new Dictionary(); + Components.RequestBodies ??= []; Components.RequestBodies.Add(id, openApiRequestBody); break; case IOpenApiLink openApiLink: - Components.Links ??= new Dictionary(); + Components.Links ??= []; Components.Links.Add(id, openApiLink); break; case IOpenApiCallback openApiCallback: - Components.Callbacks ??= new Dictionary(); + Components.Callbacks ??= []; Components.Callbacks.Add(id, openApiCallback); break; case IOpenApiPathItem openApiPathItem: - Components.PathItems ??= new Dictionary(); + Components.PathItems ??= []; Components.PathItems.Add(id, openApiPathItem); break; case IOpenApiExample openApiExample: - Components.Examples ??= new Dictionary(); + Components.Examples ??= []; Components.Examples.Add(id, openApiExample); break; case IOpenApiHeader openApiHeader: - Components.Headers ??= new Dictionary(); + Components.Headers ??= []; Components.Headers.Add(id, openApiHeader); break; case IOpenApiSecurityScheme openApiSecurityScheme: - Components.SecuritySchemes ??= new Dictionary(); + Components.SecuritySchemes ??= []; Components.SecuritySchemes.Add(id, openApiSecurityScheme); break; default: diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index 4eae8e6ce..cc9340317 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -25,7 +25,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// /// A map allowing additional information to be provided as headers. /// - public IDictionary? Headers { get; set; } = new Dictionary(); + public Dictionary? Headers { get; set; } /// /// Describes how a specific property value will be serialized depending on its type. @@ -52,7 +52,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 1470ca51a..6ffb26f2e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Models /// /// Example Object. /// - public class OpenApiExample : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiExample + public class OpenApiExample : IOpenApiExtensible, IOpenApiExample { /// public string? Summary { get; set; } @@ -28,7 +28,7 @@ public class OpenApiExample : IOpenApiReferenceable, IOpenApiExtensible, IOpenAp public JsonNode? Value { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs index e9b07bf58..7e4f9f686 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs @@ -28,7 +28,7 @@ protected OpenApiExtensibleDictionary():this([]) { } /// The dictionary of . protected OpenApiExtensibleDictionary( Dictionary dictionary, - IDictionary? extensions = null) : base(dictionary is null ? [] : dictionary) + Dictionary? extensions = null) : base(dictionary is null ? [] : dictionary) { Extensions = extensions != null ? new Dictionary(extensions) : []; } @@ -36,7 +36,7 @@ protected OpenApiExtensibleDictionary( /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } + public Dictionary? Extensions { get; set; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 2694aa26a..381ee53bb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -26,7 +26,7 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 82d17aece..62bb09b89 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -47,13 +47,13 @@ public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible public JsonNode? Example { get; set; } /// - public IDictionary? Examples { get; set; } = new Dictionary(); + public Dictionary? Examples { get; set; } /// - public IDictionary? Content { get; set; } = new Dictionary(); + public Dictionary? Content { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 93e89438c..119ae7eb1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -51,7 +51,7 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index 8aea264e6..c3c36812c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -31,7 +31,7 @@ public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index 412577580..ea9202186 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models /// /// Link Object. /// - public class OpenApiLink : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiLink + public class OpenApiLink : IOpenApiExtensible, IOpenApiLink { /// public string? OperationRef { get; set; } @@ -21,7 +21,7 @@ public class OpenApiLink : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiLi public string? OperationId { get; set; } /// - public IDictionary? Parameters { get; set; } = new Dictionary(); + public Dictionary? Parameters { get; set; } /// public RuntimeExpressionAnyWrapper? RequestBody { get; set; } @@ -33,7 +33,7 @@ public class OpenApiLink : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiLi public OpenApiServer? Server { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index 4c08ccccb..a16f8d11f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -32,7 +32,7 @@ public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible /// Examples of the media type. /// Each example object SHOULD match the media type and specified schema if present. /// - public IDictionary? Examples { get; set; } = new Dictionary(); + public Dictionary? Examples { get; set; } /// /// A map between a property name and its encoding information. @@ -40,12 +40,12 @@ public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible /// The encoding object SHALL only apply to requestBody objects /// when the media type is multipart or application/x-www-form-urlencoded. /// - public IDictionary? Encoding { get; set; } = new Dictionary(); + public Dictionary? Encoding { get; set; } /// /// Serialize to Open Api v3.0. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -119,7 +119,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // Media type does not exist in V2. } - private static void SerializeExamples(IOpenApiWriter writer, IDictionary examples) + private static void SerializeExamples(IOpenApiWriter writer, Dictionary examples) { /* Special case for writing out empty arrays as valid response examples * Check if there is any example with an empty array as its value and set the flag `hasEmptyArray` to true diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index d84417cef..05c8da5e1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -33,12 +33,12 @@ public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible /// /// REQUIRED. A map between the scope name and a short description for it. /// - public IDictionary? Scopes { get; set; } = new Dictionary(); + public Dictionary? Scopes { get; set; } /// /// Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index 758e1e02d..b46b41da1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -36,7 +36,7 @@ public class OpenApiOAuthFlows : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 23a98f3d2..592d9cb58 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -26,7 +26,7 @@ public class OpenApiOperation : IOpenApiSerializable, IOpenApiExtensible, IMetad /// A list of tags for API documentation control. /// Tags can be used for logical grouping of operations by resources or any other qualifier. /// - public ISet? Tags + public HashSet? Tags { get { @@ -73,7 +73,7 @@ public ISet? Tags /// The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. /// The list can use the Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters. /// - public IList? Parameters { get; set; } = []; + public List? Parameters { get; set; } /// /// The request body applicable for this operation. @@ -96,7 +96,7 @@ public ISet? Tags /// The key value used to identify the callback object is an expression, evaluated at runtime, /// that identifies a URL to use for the callback operation. /// - public IDictionary? Callbacks { get; set; } = new Dictionary(); + public Dictionary? Callbacks { get; set; } /// /// Declares this operation to be deprecated. Consumers SHOULD refrain from usage of the declared operation. @@ -110,22 +110,22 @@ public ISet? Tags /// This definition overrides any declared top-level security. /// To remove a top-level security declaration, an empty array can be used. /// - public IList? Security { get; set; } = new List(); + public List? Security { get; set; } /// /// An alternative server array to service this operation. /// If an alternative server object is specified at the Path Item Object or Root level, /// it will be overridden by this value. /// - public IList? Servers { get; set; } = new List(); + public List? Servers { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// - public IDictionary? Metadata { get; set; } + public Dictionary? Metadata { get; set; } /// /// Parameterless constructor @@ -138,18 +138,18 @@ public OpenApiOperation() { } public OpenApiOperation(OpenApiOperation operation) { Utils.CheckArgumentNull(operation); - Tags = operation.Tags != null ? new HashSet(operation.Tags) : null; + Tags = operation.Tags != null ? [.. operation.Tags] : null; Summary = operation.Summary ?? Summary; Description = operation.Description ?? Description; ExternalDocs = operation.ExternalDocs != null ? new(operation.ExternalDocs) : null; OperationId = operation.OperationId ?? OperationId; - Parameters = operation.Parameters != null ? new List(operation.Parameters) : null; + Parameters = operation.Parameters != null ? [.. operation.Parameters] : null; RequestBody = operation.RequestBody?.CreateShallowCopy(); Responses = operation.Responses != null ? new(operation.Responses) : null; Callbacks = operation.Callbacks != null ? new Dictionary(operation.Callbacks) : null; Deprecated = operation.Deprecated; - Security = operation.Security != null ? new List(operation.Security) : null; - Servers = operation.Servers != null ? new List(operation.Servers) : null; + Security = operation.Security != null ? [.. operation.Security] : null; + Servers = operation.Servers != null ? [.. operation.Servers] : null; Extensions = operation.Extensions != null ? new Dictionary(operation.Extensions) : null; Metadata = operation.Metadata != null ? new Dictionary(operation.Metadata) : null; } @@ -293,7 +293,7 @@ public void SerializeAsV2(IOpenApiWriter writer) { var produces = Responses .Where(static r => r.Value.Content != null) - .SelectMany(static r => r.Value.Content?.Keys ?? []) + .SelectMany(static r => r.Value.Content?.Keys ?? Enumerable.Empty()) .Where(static m => !string.IsNullOrEmpty(m)) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray(); diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index 652e65b3d..fd74c2b57 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -61,16 +61,16 @@ public bool Explode public IOpenApiSchema? Schema { get; set; } /// - public IDictionary? Examples { get; set; } = new Dictionary(); + public Dictionary? Examples { get; set; } /// public JsonNode? Example { get; set; } /// - public IDictionary? Content { get; set; } = new Dictionary(); + public Dictionary? Content { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// A parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 6e89d9684..a001b922c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Models /// /// Path Item Object: to describe the operations available on a single path. /// - public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiPathItem + public class OpenApiPathItem : IOpenApiExtensible, IOpenApiPathItem { /// public string? Summary { get; set; } @@ -23,17 +23,16 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA public string? Description { get; set; } /// - public IDictionary? Operations { get; set; } - = new Dictionary(); + public Dictionary? Operations { get; set; } /// - public IList? Servers { get; set; } = []; + public List? Servers { get; set; } /// - public IList? Parameters { get; set; } = []; + public List? Parameters { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Add one operation into this path item. @@ -42,10 +41,8 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA /// The operation item. public void AddOperation(HttpMethod operationType, OpenApiOperation operation) { - if (Operations is not null) - { - Operations[operationType] = operation; - } + Operations ??= []; + Operations[operationType] = operation; } /// @@ -62,8 +59,8 @@ internal OpenApiPathItem(IOpenApiPathItem pathItem) Summary = pathItem.Summary ?? Summary; Description = pathItem.Description ?? Description; Operations = pathItem.Operations != null ? new Dictionary(pathItem.Operations) : null; - Servers = pathItem.Servers != null ? new List(pathItem.Servers) : null; - Parameters = pathItem.Parameters != null ? new List(pathItem.Parameters) : null; + Servers = pathItem.Servers != null ? [.. pathItem.Servers] : null; + Parameters = pathItem.Parameters != null ? [.. pathItem.Parameters] : null; Extensions = pathItem.Extensions != null ? new Dictionary(pathItem.Extensions) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 70d1a1309..302cfc5ae 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Models /// /// Request Body Object /// - public class OpenApiRequestBody : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiRequestBody + public class OpenApiRequestBody : IOpenApiExtensible, IOpenApiRequestBody { /// public string? Description { get; set; } @@ -25,10 +25,10 @@ public class OpenApiRequestBody : IOpenApiReferenceable, IOpenApiExtensible, IOp public bool Required { get; set; } /// - public IDictionary? Content { get; set; } = new Dictionary(); + public Dictionary? Content { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameter-less constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 9c8459e2b..13ab81152 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -13,22 +13,22 @@ namespace Microsoft.OpenApi.Models /// /// Response object. /// - public class OpenApiResponse : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiResponse + public class OpenApiResponse : IOpenApiExtensible, IOpenApiResponse { /// public string? Description { get; set; } /// - public IDictionary? Headers { get; set; } = new Dictionary(); + public Dictionary? Headers { get; set; } /// - public IDictionary? Content { get; set; } = new Dictionary(); + public Dictionary? Content { get; set; } /// - public IDictionary? Links { get; set; } = new Dictionary(); + public Dictionary? Links { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -136,7 +136,7 @@ public void SerializeAsV2(IOpenApiWriter writer) foreach (var example in Content .Select(static x => x.Value.Examples) - .OfType>() + .OfType>() .SelectMany(static x => x)) { writer.WritePropertyName(example.Key); diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 8c1f5d596..28c3e30c9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -33,7 +33,7 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiSchema public string? Comment { get; set; } /// - public IDictionary? Vocabulary { get; set; } + public Dictionary? Vocabulary { get; set; } /// public string? DynamicRef { get; set; } @@ -42,7 +42,7 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiSchema public string? DynamicAnchor { get; set; } /// - public IDictionary? Definitions { get; set; } + public Dictionary? Definitions { get; set; } private string? _exclusiveMaximum; /// @@ -173,19 +173,19 @@ public string? Minimum public bool WriteOnly { get; set; } /// - public IList? AllOf { get; set; } = []; + public List? AllOf { get; set; } /// - public IList? OneOf { get; set; } = []; + public List? OneOf { get; set; } /// - public IList? AnyOf { get; set; } = []; + public List? AnyOf { get; set; } /// public IOpenApiSchema? Not { get; set; } /// - public ISet? Required { get; set; } = new HashSet(); + public HashSet? Required { get; set; } /// public IOpenApiSchema? Items { get; set; } @@ -200,10 +200,10 @@ public string? Minimum public bool? UniqueItems { get; set; } /// - public IDictionary? Properties { get; set; } = new Dictionary(StringComparer.Ordinal); + public Dictionary? Properties { get; set; } /// - public IDictionary? PatternProperties { get; set; } = new Dictionary(StringComparer.Ordinal); + public Dictionary? PatternProperties { get; set; } /// public int? MaxProperties { get; set; } @@ -224,13 +224,13 @@ public string? Minimum public JsonNode? Example { get; set; } /// - public IList? Examples { get; set; } + public List? Examples { get; set; } /// - public IList? Enum { get; set; } = new List(); + public List? Enum { get; set; } /// - public bool UnevaluatedProperties { get; set;} + public bool UnevaluatedProperties { get; set; } /// public OpenApiExternalDocs? ExternalDocs { get; set; } @@ -242,16 +242,16 @@ public string? Minimum public OpenApiXml? Xml { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// - public IDictionary? UnrecognizedKeywords { get; set; } = new Dictionary(); + public Dictionary? UnrecognizedKeywords { get; set; } /// - public IDictionary? Annotations { get; set; } + public Dictionary? Annotations { get; set; } /// - public IDictionary>? DependentRequired { get; set; } = new Dictionary>(); + public Dictionary>? DependentRequired { get; set; } /// /// Parameterless constructor @@ -294,11 +294,11 @@ internal OpenApiSchema(IOpenApiSchema schema) Default = schema.Default != null ? JsonNodeCloneHelper.Clone(schema.Default) : null; ReadOnly = schema.ReadOnly; WriteOnly = schema.WriteOnly; - AllOf = schema.AllOf != null ? new List(schema.AllOf) : null; - OneOf = schema.OneOf != null ? new List(schema.OneOf) : null; - AnyOf = schema.AnyOf != null ? new List(schema.AnyOf) : null; + AllOf = schema.AllOf != null ? [.. schema.AllOf] : null; + OneOf = schema.OneOf != null ? [.. schema.OneOf] : null; + AnyOf = schema.AnyOf != null ? [.. schema.AnyOf] : null; Not = schema.Not?.CreateShallowCopy(); - Required = schema.Required != null ? new HashSet(schema.Required) : null; + Required = schema.Required != null ? [.. schema.Required] : null; Items = schema.Items?.CreateShallowCopy(); MaxItems = schema.MaxItems ?? MaxItems; MinItems = schema.MinItems ?? MinItems; @@ -309,17 +309,17 @@ internal OpenApiSchema(IOpenApiSchema schema) MinProperties = schema.MinProperties ?? MinProperties; AdditionalPropertiesAllowed = schema.AdditionalPropertiesAllowed; AdditionalProperties = schema.AdditionalProperties?.CreateShallowCopy(); - Discriminator = schema.Discriminator != null ? new(schema.Discriminator) : null; + Discriminator = schema.Discriminator != null ? new(schema.Discriminator) : null; Example = schema.Example != null ? JsonNodeCloneHelper.Clone(schema.Example) : null; - Examples = schema.Examples != null ? new List(schema.Examples) : null; - Enum = schema.Enum != null ? new List(schema.Enum) : null; + Examples = schema.Examples != null ? [.. schema.Examples] : null; + Enum = schema.Enum != null ? [.. schema.Enum] : null; ExternalDocs = schema.ExternalDocs != null ? new(schema.ExternalDocs) : null; Deprecated = schema.Deprecated; Xml = schema.Xml != null ? new(schema.Xml) : null; Extensions = schema.Extensions != null ? new Dictionary(schema.Extensions) : null; Annotations = schema.Annotations != null ? new Dictionary(schema.Annotations) : null; UnrecognizedKeywords = schema.UnrecognizedKeywords != null ? new Dictionary(schema.UnrecognizedKeywords) : null; - DependentRequired = schema.DependentRequired != null ? new Dictionary>(schema.DependentRequired) : null; + DependentRequired = schema.DependentRequired != null ? new Dictionary>(schema.DependentRequired) : null; } /// @@ -426,7 +426,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version writer.WriteProperty(OpenApiConstants.MinProperties, MinProperties); // required - writer.WriteOptionalCollection(OpenApiConstants.Required, Required, (w, s) => + writer.WriteOptionalCollection(OpenApiConstants.Required, Required, (w, s) => { if (!string.IsNullOrEmpty(s) && s is not null) { @@ -507,7 +507,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version // Unrecognized keywords if (UnrecognizedKeywords is not null && UnrecognizedKeywords.Any()) { - writer.WriteOptionalMap(OpenApiConstants.UnrecognizedKeywords, UnrecognizedKeywords, (w,s) => w.WriteAny(s)); + writer.WriteOptionalMap(OpenApiConstants.UnrecognizedKeywords, UnrecognizedKeywords, (w, s) => w.WriteAny(s)); } writer.WriteEndObject(); @@ -612,7 +612,7 @@ private void WriteFormatProperty(IOpenApiWriter writer) /// The property name that will be serialized. private void SerializeAsV2( IOpenApiWriter writer, - ISet? parentRequiredProperties, + HashSet? parentRequiredProperties, string? propertyName) { parentRequiredProperties ??= new HashSet(); @@ -670,7 +670,7 @@ private void SerializeAsV2( writer.WriteProperty(OpenApiConstants.MinProperties, MinProperties); // required - writer.WriteOptionalCollection(OpenApiConstants.Required, Required, (w, s) => + writer.WriteOptionalCollection(OpenApiConstants.Required, Required, (w, s) => { if (!string.IsNullOrEmpty(s) && s is not null) { @@ -754,7 +754,7 @@ private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer, // check whether nullable is true for upcasting purposes var isNullable = (Type.HasValue && Type.Value.HasFlag(JsonSchemaType.Null)) || Extensions is not null && - Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) && + Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) && nullExtRawValue is OpenApiAny { Node: JsonNode jsonNode } && jsonNode.GetValueKind() is JsonValueKind.True; if (type is null) @@ -766,7 +766,7 @@ Extensions is not null && } else if (!HasMultipleTypes(type.Value)) { - + switch (version) { case OpenApiSpecVersion.OpenApi3_1 when isNullable: @@ -799,13 +799,13 @@ where type.Value.HasFlag(flag) select flag).ToList(); writer.WriteOptionalCollection(OpenApiConstants.Type, list, (w, s) => { - foreach(var item in s.ToIdentifiers()) + foreach (var item in s.ToIdentifiers()) { w.WriteValue(item); } }); } - } + } } private static bool IsPowerOfTwo(int x) @@ -829,7 +829,7 @@ where temporaryType.HasFlag(flag) select flag.ToFirstIdentifier()).ToList(); if (list.Count > 1) { - writer.WriteOptionalCollection(OpenApiConstants.Type, list, (w, s) => + writer.WriteOptionalCollection(OpenApiConstants.Type, list, (w, s) => { if (!string.IsNullOrEmpty(s) && s is not null) { @@ -849,7 +849,7 @@ where temporaryType.HasFlag(flag) private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(typeof(JsonSchemaType)); #endif - private void DowncastTypeArrayToV2OrV3(JsonSchemaType schemaType, IOpenApiWriter writer, OpenApiSpecVersion version) + private static void DowncastTypeArrayToV2OrV3(JsonSchemaType schemaType, IOpenApiWriter writer, OpenApiSpecVersion version) { /* If the array has one non-null value, emit Type as string * If the array has one null value, emit x-nullable as true diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs index 7b2e70d3c..f9d40682b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityRequirement.cs @@ -19,7 +19,7 @@ namespace Microsoft.OpenApi.Models /// then the value is a list of scope names required for the execution. /// For other security scheme types, the array MUST be empty. /// - public class OpenApiSecurityRequirement : Dictionary>, + public class OpenApiSecurityRequirement : Dictionary>, IOpenApiSerializable { /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index 7d254a3d2..992fe7986 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.Models /// /// Security Scheme Object. /// - public class OpenApiSecurityScheme : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiSecurityScheme + public class OpenApiSecurityScheme : IOpenApiExtensible, IOpenApiSecurityScheme { /// public SecuritySchemeType? Type { get; set; } @@ -40,7 +40,7 @@ public class OpenApiSecurityScheme : IOpenApiExtensible, IOpenApiReferenceable, public Uri? OpenIdConnectUrl { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index a15c6068e..9c5b3cfca 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -28,13 +28,12 @@ public class OpenApiServer : IOpenApiSerializable, IOpenApiExtensible /// /// A map between a variable name and its value. The value is used for substitution in the server's URL template. /// - public IDictionary? Variables { get; set; } = - new Dictionary(); + public Dictionary? Variables { get; set; } /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 9c46f20a8..793c94d6c 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -34,7 +34,7 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 48ac2960c..253fab1de 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models /// /// Tag Object. /// - public class OpenApiTag : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiTag, IOpenApiDescribedElement + public class OpenApiTag : IOpenApiExtensible, IOpenApiTag, IOpenApiDescribedElement { /// public string? Name { get; set; } @@ -24,7 +24,7 @@ public class OpenApiTag : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiTag public OpenApiExternalDocs? ExternalDocs { get; set; } /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index c0503e14d..ae8a94a46 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -43,7 +43,7 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public IDictionary? Extensions { get; set; } = new Dictionary(); + public Dictionary? Extensions { get; set; } /// /// Parameterless constructor diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index d1a06da15..1211561e4 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -41,7 +41,7 @@ private OpenApiCallbackReference(OpenApiCallbackReference callback):base(callbac public Dictionary? PathItems { get => Target?.PathItems; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(IOpenApiCallback source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs index b1c1ae8ae..59cb7319e 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -51,7 +51,7 @@ public string? Summary } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public string? ExternalValue { get => Target?.ExternalValue; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs index cd843de57..fa8fe15eb 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -68,13 +68,13 @@ public string? Description public JsonNode? Example { get => Target?.Example; } /// - public IDictionary? Examples { get => Target?.Examples; } + public Dictionary? Examples { get => Target?.Examples; } /// - public IDictionary? Content { get => Target?.Content; } + public Dictionary? Content { get => Target?.Content; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiHeader CopyReferenceAsTargetElementWithOverrides(IOpenApiHeader source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs index 8c23cdf35..71f52ecd9 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -52,13 +52,13 @@ public string? Description public OpenApiServer? Server { get => Target?.Server; } /// - public IDictionary? Parameters { get => Target?.Parameters; } + public Dictionary? Parameters { get => Target?.Parameters; } /// public RuntimeExpressionAnyWrapper? RequestBody { get => Target?.RequestBody; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override void SerializeAsV2(IOpenApiWriter writer) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs index 40ecb69eb..ae9322e41 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -61,7 +61,7 @@ public string? Description public IOpenApiSchema? Schema { get => Target?.Schema; } /// - public IDictionary? Examples { get => Target?.Examples; } + public Dictionary? Examples { get => Target?.Examples; } /// public JsonNode? Example { get => Target?.Example; } @@ -76,10 +76,10 @@ public string? Description public bool Explode { get => Target?.Explode ?? default; } /// - public IDictionary? Content { get => Target?.Content; } + public Dictionary? Content { get => Target?.Content; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiParameter CopyReferenceAsTargetElementWithOverrides(IOpenApiParameter source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index bfd9f8ceb..a6ae2d405 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -53,16 +53,16 @@ public string? Description } /// - public IDictionary? Operations { get => Target?.Operations; } + public Dictionary? Operations { get => Target?.Operations; } /// - public IList? Servers { get => Target?.Servers; } + public List? Servers { get => Target?.Servers; } /// - public IList? Parameters { get => Target?.Parameters; } + public List? Parameters { get => Target?.Parameters; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(IOpenApiPathItem source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs index 8beb3e604..f6bee476b 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -45,13 +45,13 @@ public string? Description } /// - public IDictionary? Content { get => Target?.Content; } + public Dictionary? Content { get => Target?.Content; } /// public bool Required { get => Target?.Required ?? false; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiRequestBody CopyReferenceAsTargetElementWithOverrides(IOpenApiRequestBody source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs index cc78f6080..648b9c4c6 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -43,16 +43,16 @@ public string? Description } /// - public IDictionary? Content { get => Target?.Content; } + public Dictionary? Content { get => Target?.Content; } /// - public IDictionary? Headers { get => Target?.Headers; } + public Dictionary? Headers { get => Target?.Headers; } /// - public IDictionary? Links { get => Target?.Links; } + public Dictionary? Links { get => Target?.Links; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public override IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(IOpenApiResponse source) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index fb817f56b..7dd3ea3e5 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -52,13 +52,13 @@ public string? Description /// public string? Comment { get => Target?.Comment; } /// - public IDictionary? Vocabulary { get => Target?.Vocabulary; } + public Dictionary? Vocabulary { get => Target?.Vocabulary; } /// public string? DynamicRef { get => Target?.DynamicRef; } /// public string? DynamicAnchor { get => Target?.DynamicAnchor; } /// - public IDictionary? Definitions { get => Target?.Definitions; } + public Dictionary? Definitions { get => Target?.Definitions; } /// public string? ExclusiveMaximum { get => Target?.ExclusiveMaximum; } /// @@ -88,15 +88,15 @@ public string? Description /// public bool WriteOnly { get => Target?.WriteOnly ?? false; } /// - public IList? AllOf { get => Target?.AllOf; } + public List? AllOf { get => Target?.AllOf; } /// - public IList? OneOf { get => Target?.OneOf; } + public List? OneOf { get => Target?.OneOf; } /// - public IList? AnyOf { get => Target?.AnyOf; } + public List? AnyOf { get => Target?.AnyOf; } /// public IOpenApiSchema? Not { get => Target?.Not; } /// - public ISet? Required { get => Target?.Required; } + public HashSet? Required { get => Target?.Required; } /// public IOpenApiSchema? Items { get => Target?.Items; } /// @@ -106,9 +106,9 @@ public string? Description /// public bool? UniqueItems { get => Target?.UniqueItems; } /// - public IDictionary? Properties { get => Target?.Properties; } + public Dictionary? Properties { get => Target?.Properties; } /// - public IDictionary? PatternProperties { get => Target?.PatternProperties; } + public Dictionary? PatternProperties { get => Target?.PatternProperties; } /// public int? MaxProperties { get => Target?.MaxProperties; } /// @@ -122,9 +122,9 @@ public string? Description /// public JsonNode? Example { get => Target?.Example; } /// - public IList? Examples { get => Target?.Examples; } + public List? Examples { get => Target?.Examples; } /// - public IList? Enum { get => Target?.Enum; } + public List? Enum { get => Target?.Enum; } /// public bool UnevaluatedProperties { get => Target?.UnevaluatedProperties ?? false; } /// @@ -134,16 +134,16 @@ public string? Description /// public OpenApiXml? Xml { get => Target?.Xml; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// - public IDictionary? UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; } + public Dictionary? UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; } /// - public IDictionary? Annotations { get => Target?.Annotations; } + public Dictionary? Annotations { get => Target?.Annotations; } /// - public IDictionary>? DependentRequired { get => Target?.DependentRequired; } + public Dictionary>? DependentRequired { get => Target?.DependentRequired; } /// public override void SerializeAsV31(IOpenApiWriter writer) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index 44741467b..ff9c5b396 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -57,7 +57,7 @@ public string? Description public Uri? OpenIdConnectUrl { get => Target?.OpenIdConnectUrl; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public SecuritySchemeType? Type { get => Target?.Type; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs index 59255a8b6..cd3af84ba 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs @@ -57,7 +57,7 @@ public string? Description public OpenApiExternalDocs? ExternalDocs { get => Target?.ExternalDocs; } /// - public IDictionary? Extensions { get => Target?.Extensions; } + public Dictionary? Extensions { get => Target?.Extensions; } /// public string? Name { get => Target?.Name; } diff --git a/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs b/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs index 247bb2ba8..be718c28d 100644 --- a/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs +++ b/src/Microsoft.OpenApi/Reader/OpenApiDiagnostic.cs @@ -15,12 +15,12 @@ public class OpenApiDiagnostic : IDiagnostic /// /// List of all errors. /// - public IList Errors { get; set; } = new List(); + public List Errors { get; set; } = []; /// /// List of all warnings /// - public IList Warnings { get; set; } = new List(); + public List Warnings { get; set; } = []; /// /// Open API specification version of the document parsed. diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs index 873f0df15..a096b5a08 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyListFieldMapParameter.cs @@ -14,8 +14,8 @@ internal class AnyListFieldMapParameter /// Constructor /// public AnyListFieldMapParameter( - Func> propertyGetter, - Action> propertySetter, + Func> propertyGetter, + Action> propertySetter, Func? SchemaGetter = null) { this.PropertyGetter = propertyGetter; @@ -26,12 +26,12 @@ public AnyListFieldMapParameter( /// /// Function to retrieve the value of the property. /// - public Func> PropertyGetter { get; } + public Func> PropertyGetter { get; } /// /// Function to set the value of the property. /// - public Action> PropertySetter { get; } + public Action> PropertySetter { get; } /// /// Function to get the schema to apply to the property. diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs index 6a16f4e46..883aa137b 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/AnyMapFieldMapParameter.cs @@ -15,7 +15,7 @@ internal class AnyMapFieldMapParameter /// Constructor /// public AnyMapFieldMapParameter( - Func?> propertyMapGetter, + Func?> propertyMapGetter, Func propertyGetter, Action propertySetter, Func schemaGetter) @@ -29,7 +29,7 @@ public AnyMapFieldMapParameter( /// /// Function to retrieve the property that is a map from string to an inner element containing IOpenApiAny. /// - public Func?> PropertyMapGetter { get; } + public Func?> PropertyMapGetter { get; } /// /// Function to retrieve the value of the property from an inner element. diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs index 3d3ef71af..ae7adefa6 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs @@ -102,7 +102,7 @@ public override Dictionary CreateSimpleMap(Func map) return nodes.ToDictionary(k => k.key, v => v.value); } - public override Dictionary> CreateArrayMap(Func map, OpenApiDocument? openApiDocument) + public override Dictionary> CreateArrayMap(Func map, OpenApiDocument? openApiDocument) { var jsonMap = _node ?? throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context); @@ -116,7 +116,7 @@ public override Dictionary> CreateArrayMap(Func values = new HashSet(arrayNode.OfType().Select(item => map(new ValueNode(Context, item), openApiDocument))); + HashSet values = new HashSet(arrayNode.OfType().Select(item => map(new ValueNode(Context, item), openApiDocument))); return (key, values); diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs index 699022193..6c62fa0b8 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/ParseNode.cs @@ -86,7 +86,7 @@ public virtual List CreateListOfAny() throw new OpenApiReaderException("Cannot create a list from this type of node.", Context); } - public virtual Dictionary> CreateArrayMap(Func map, OpenApiDocument? openApiDocument) + public virtual Dictionary> CreateArrayMap(Func map, OpenApiDocument? openApiDocument) { throw new OpenApiReaderException("Cannot create array map from this type of node.", Context); } diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs index 9517e5363..4a3fd0336 100644 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs +++ b/src/Microsoft.OpenApi/Reader/ParseNodes/PropertyNode.cs @@ -25,8 +25,8 @@ public PropertyNode(ParsingContext context, string name, JsonNode node) : base( public void ParseField( T parentInstance, - IDictionary> fixedFields, - IDictionary, Action> patternFields, + Dictionary> fixedFields, + Dictionary, Action> patternFields, OpenApiDocument hostDocument) { if (fixedFields.TryGetValue(Name, out var fixedFieldMap)) diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs index f7cbe711a..369d03470 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs @@ -117,7 +117,7 @@ internal static partial class OpenApiV2Deserializer {s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))} }; - private static void MakeServers(IList servers, ParsingContext context, RootNode rootNode) + private static void MakeServers(List servers, ParsingContext context, RootNode rootNode) { var host = context.GetFromTempStorage("host"); var basePath = context.GetFromTempStorage("basePath"); @@ -148,7 +148,7 @@ private static void MakeServers(IList servers, ParsingContext con { host = host ?? defaultUrl.GetComponents(UriComponents.NormalizedHost, UriFormat.SafeUnescaped); basePath = basePath ?? defaultUrl.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped); - schemes = schemes ?? new List { defaultUrl.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped) }; + schemes = schemes ?? [defaultUrl.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped)]; } else if (String.IsNullOrEmpty(host) && String.IsNullOrEmpty(basePath)) { @@ -250,7 +250,7 @@ public static OpenApiDocument LoadOpenApi(RootNode rootNode) // Post Process OpenApi Object if (openApiDoc.Servers == null) { - openApiDoc.Servers = new List(); + openApiDoc.Servers = []; } MakeServers(openApiDoc.Servers, openApiNode.Context, rootNode); @@ -310,8 +310,8 @@ private static bool IsHostValid(string host) internal class RequestBodyReferenceFixer : OpenApiVisitorBase { - private readonly IDictionary _requestBodies; - public RequestBodyReferenceFixer(IDictionary requestBodies) + private readonly Dictionary _requestBodies; + public RequestBodyReferenceFixer(Dictionary requestBodies) { _requestBodies = requestBodies; } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs index 4bd28a18d..4e53273e8 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Models.Interfaces; using System; +using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Reader.V2 { @@ -195,7 +196,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List>(TempStorageKeys.OperationConsumes) ?? context.GetFromTempStorage>(TempStorageKeys.GlobalConsumes) ?? - new List { "application/x-www-form-urlencoded" }; + ["application/x-www-form-urlencoded"]; var formBody = new OpenApiRequestBody { @@ -222,7 +223,7 @@ internal static IOpenApiRequestBody CreateRequestBody( { var consumes = context.GetFromTempStorage>(TempStorageKeys.OperationConsumes) ?? context.GetFromTempStorage>(TempStorageKeys.GlobalConsumes) ?? - new List { "application/json" }; + ["application/json"]; var requestBody = new OpenApiRequestBody { @@ -238,8 +239,9 @@ internal static IOpenApiRequestBody CreateRequestBody( Extensions = bodyParameter.Extensions }; - if (requestBody.Extensions is not null && bodyParameter.Name is not null) + if (bodyParameter.Name is not null) { + requestBody.Extensions ??= []; requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiAny(bodyParameter.Name); } return requestBody; diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs index 653208578..3560a3258 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs @@ -62,7 +62,7 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P { if (response.Content == null) { - response.Content = new Dictionary(); + response.Content = []; } else if (context.GetFromTempStorage(TempStorageKeys.ResponseProducesSet, response)) { @@ -72,11 +72,10 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P var produces = context.GetFromTempStorage>(TempStorageKeys.OperationProduces) ?? context.GetFromTempStorage>(TempStorageKeys.GlobalProduces) - ?? context.DefaultContentType ?? new List { "application/octet-stream" }; + ?? context.DefaultContentType ?? ["application/octet-stream"]; var schema = context.GetFromTempStorage(TempStorageKeys.ResponseSchema, response); - var examples = context.GetFromTempStorage>(TempStorageKeys.Examples, response) - ?? new Dictionary(); + var examples = context.GetFromTempStorage>(TempStorageKeys.Examples, response); foreach (var produce in produces) { diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs index 020472c7a..71265aa8c 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Text.Json.Nodes; namespace Microsoft.OpenApi.Reader.V31 { @@ -382,8 +383,9 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu { propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields, hostDocument); } - else if (schema.UnrecognizedKeywords is not null && propertyNode.JsonNode is not null) + else if (propertyNode.JsonNode is not null) { + schema.UnrecognizedKeywords ??= new Dictionary(StringComparer.Ordinal); schema.UnrecognizedKeywords[propertyNode.Name] = propertyNode.JsonNode; } } diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs index 3e010be9b..da404f4c0 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiV31VersionService.cs @@ -29,7 +29,7 @@ public OpenApiV31VersionService(OpenApiDiagnostic diagnostic) Diagnostic = diagnostic; } - private readonly IDictionary> _loaders = new Dictionary> + private readonly Dictionary> _loaders = new Dictionary> { [typeof(OpenApiAny)] = OpenApiV31Deserializer.LoadAny, [typeof(OpenApiCallback)] = OpenApiV31Deserializer.LoadCallback, diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index 6874b3f8d..96932490d 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -89,8 +89,9 @@ private void AddSchemaToComponents(IOpenApiSchema? schema, string? referenceId = { EnsureComponentsExist(); EnsureSchemasExist(); - if (Components.Schemas is not null && referenceId is not null && schema is not null && !Components.Schemas.ContainsKey(referenceId)) + if (referenceId is not null && schema is not null && !(Components.Schemas?.ContainsKey(referenceId) ?? false)) { + Components.Schemas ??= []; Components.Schemas.Add(referenceId, schema); } } @@ -99,8 +100,9 @@ private void AddParameterToComponents(IOpenApiParameter? parameter, string? refe { EnsureComponentsExist(); EnsureParametersExist(); - if (Components.Parameters is not null && parameter is not null && referenceId is not null && !Components.Parameters.ContainsKey(referenceId)) + if (parameter is not null && referenceId is not null && !(Components.Parameters?.ContainsKey(referenceId) ?? false)) { + Components.Parameters ??= []; Components.Parameters.Add(referenceId, parameter); } } @@ -109,8 +111,9 @@ private void AddResponseToComponents(IOpenApiResponse? response, string? referen { EnsureComponentsExist(); EnsureResponsesExist(); - if (Components.Responses is not null && referenceId is not null && response is not null && !Components.Responses.ContainsKey(referenceId)) + if (referenceId is not null && response is not null && !(Components.Responses?.ContainsKey(referenceId) ?? false)) { + Components.Responses ??= []; Components.Responses.Add(referenceId, response); } } @@ -118,8 +121,9 @@ private void AddRequestBodyToComponents(IOpenApiRequestBody? requestBody, string { EnsureComponentsExist(); EnsureRequestBodiesExist(); - if (Components.RequestBodies is not null && requestBody is not null && referenceId is not null && !Components.RequestBodies.ContainsKey(referenceId)) + if (requestBody is not null && referenceId is not null && !(Components.RequestBodies?.ContainsKey(referenceId) ?? false)) { + Components.RequestBodies ??= []; Components.RequestBodies.Add(referenceId, requestBody); } } @@ -127,8 +131,9 @@ private void AddLinkToComponents(IOpenApiLink? link, string? referenceId = null) { EnsureComponentsExist(); EnsureLinksExist(); - if (Components.Links is not null && link is not null && referenceId is not null && !Components.Links.ContainsKey(referenceId)) + if (link is not null && referenceId is not null && !(Components.Links?.ContainsKey(referenceId) ?? false)) { + Components.Links ??= []; Components.Links.Add(referenceId, link); } } @@ -136,8 +141,9 @@ private void AddCallbackToComponents(IOpenApiCallback? callback, string? referen { EnsureComponentsExist(); EnsureCallbacksExist(); - if (Components.Callbacks is not null && callback is not null && referenceId is not null && !Components.Callbacks.ContainsKey(referenceId)) + if (callback is not null && referenceId is not null && !(Components.Callbacks?.ContainsKey(referenceId) ?? false)) { + Components.Callbacks ??= []; Components.Callbacks.Add(referenceId, callback); } } @@ -145,8 +151,9 @@ private void AddHeaderToComponents(IOpenApiHeader? header, string? referenceId = { EnsureComponentsExist(); EnsureHeadersExist(); - if (Components.Headers is not null && header is not null && referenceId is not null && !Components.Headers.ContainsKey(referenceId)) + if (header is not null && referenceId is not null && !(Components.Headers?.ContainsKey(referenceId) ?? false)) { + Components.Headers ??= []; Components.Headers.Add(referenceId, header); } } @@ -154,8 +161,9 @@ private void AddExampleToComponents(IOpenApiExample? example, string? referenceI { EnsureComponentsExist(); EnsureExamplesExist(); - if (Components.Examples is not null && example is not null && referenceId is not null && !Components.Examples.ContainsKey(referenceId)) + if (example is not null && referenceId is not null && !(Components.Examples?.ContainsKey(referenceId) ?? false)) { + Components.Examples ??= []; Components.Examples.Add(referenceId, example); } } @@ -163,8 +171,9 @@ private void AddPathItemToComponents(IOpenApiPathItem? pathItem, string? referen { EnsureComponentsExist(); EnsurePathItemsExist(); - if (Components.PathItems is not null && pathItem is not null && referenceId is not null && !Components.PathItems.ContainsKey(referenceId)) + if (pathItem is not null && referenceId is not null && !(Components.PathItems?.ContainsKey(referenceId) ?? false)) { + Components.PathItems ??= []; Components.PathItems.Add(referenceId, pathItem); } } @@ -172,8 +181,9 @@ private void AddSecuritySchemeToComponents(IOpenApiSecurityScheme? securitySchem { EnsureComponentsExist(); EnsureSecuritySchemesExist(); - if (Components.SecuritySchemes is not null && securityScheme is not null && referenceId is not null && !Components.SecuritySchemes.ContainsKey(referenceId)) + if (securityScheme is not null && referenceId is not null && !(Components.SecuritySchemes?.ContainsKey(referenceId) ?? false)) { + Components.SecuritySchemes ??= []; Components.SecuritySchemes.Add(referenceId, securityScheme); } } @@ -198,7 +208,7 @@ private void EnsureSchemasExist() { if (_target.Components is not null) { - _target.Components.Schemas ??= new Dictionary(); + _target.Components.Schemas ??= []; } } @@ -206,7 +216,7 @@ private void EnsureParametersExist() { if (_target.Components is not null) { - _target.Components.Parameters ??= new Dictionary(); + _target.Components.Parameters ??= []; } } @@ -214,7 +224,7 @@ private void EnsureResponsesExist() { if (_target.Components is not null) { - _target.Components.Responses ??= new Dictionary(); + _target.Components.Responses ??= []; } } @@ -222,7 +232,7 @@ private void EnsureRequestBodiesExist() { if (_target.Components is not null) { - _target.Components.RequestBodies ??= new Dictionary(); + _target.Components.RequestBodies ??= []; } } @@ -230,7 +240,7 @@ private void EnsureExamplesExist() { if (_target.Components is not null) { - _target.Components.Examples ??= new Dictionary(); + _target.Components.Examples ??= []; } } @@ -238,7 +248,7 @@ private void EnsureHeadersExist() { if (_target.Components is not null) { - _target.Components.Headers ??= new Dictionary(); + _target.Components.Headers ??= []; } } @@ -246,7 +256,7 @@ private void EnsureCallbacksExist() { if (_target.Components is not null) { - _target.Components.Callbacks ??= new Dictionary(); + _target.Components.Callbacks ??= []; } } @@ -254,7 +264,7 @@ private void EnsureLinksExist() { if (_target.Components is not null) { - _target.Components.Links ??= new Dictionary(); + _target.Components.Links ??= []; } } @@ -262,14 +272,14 @@ private void EnsureSecuritySchemesExist() { if (_target.Components is not null) { - _target.Components.SecuritySchemes ??= new Dictionary(); + _target.Components.SecuritySchemes ??= []; } } private void EnsurePathItemsExist() { if (_target.Components is not null) { - _target.Components.PathItems = new Dictionary(); + _target.Components.PathItems = []; } } } diff --git a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs index 82a09c249..f58053b1c 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs @@ -109,17 +109,19 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun } } - if (result.CurrentKeys?.Operation != null && result.Operation != null) + if (result.CurrentKeys?.Operation != null && result.Operation != null && pathItem is OpenApiPathItem openApiPathItem) { - pathItem?.Operations?.Add(result.CurrentKeys.Operation, result.Operation); + openApiPathItem.Operations ??= []; + openApiPathItem.Operations?.Add(result.CurrentKeys.Operation, result.Operation); if (result.Parameters?.Any() ?? false) { + openApiPathItem.Parameters ??= []; foreach (var parameter in result.Parameters) { - if (pathItem?.Parameters is not null && !pathItem.Parameters.Contains(parameter)) + if (openApiPathItem?.Parameters is not null && !openApiPathItem.Parameters.Contains(parameter)) { - pathItem.Parameters.Add(parameter); + openApiPathItem.Parameters.Add(parameter); } } } @@ -151,7 +153,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary? GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) + private static Dictionary? GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) { if (relativeUrl.Equals("/", StringComparison.Ordinal) && rootNode.HasOperations(label)) { @@ -160,7 +162,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary? operations = null; + Dictionary? operations = null; var targetChild = rootNode; @@ -228,7 +230,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary FindOperations(OpenApiDocument sourceDocument, Func predicate) + private static List FindOperations(OpenApiDocument sourceDocument, Func predicate) { var search = new OperationSearch(predicate); var walker = new OpenApiWalker(search); @@ -260,7 +262,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon if (target?.Schemas is not null && !target.Schemas.ContainsKey(item.Key)) { moreStuff = true; - target.Schemas.Add(item); + target.Schemas.Add(item.Key, item.Value); } } } @@ -272,7 +274,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon if (target?.Parameters is not null && !target.Parameters.ContainsKey(item.Key)) { moreStuff = true; - target.Parameters.Add(item); + target.Parameters.Add(item.Key, item.Value); } } } @@ -284,7 +286,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon if (target?.Responses is not null && !target.Responses.ContainsKey(item.Key)) { moreStuff = true; - target.Responses.Add(item); + target.Responses.Add(item.Key, item.Value); } } } @@ -295,7 +297,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.RequestBodies is not null && !target.RequestBodies.ContainsKey(item.Key))) { moreStuff = true; - target?.RequestBodies?.Add(item); + target?.RequestBodies?.Add(item.Key, item.Value); } } @@ -305,7 +307,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.Headers is not null && !target.Headers.ContainsKey(item.Key))) { moreStuff = true; - target?.Headers?.Add(item); + target?.Headers?.Add(item.Key, item.Value); } } @@ -315,7 +317,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.Links is not null && !target.Links.ContainsKey(item.Key))) { moreStuff = true; - target?.Links?.Add(item); + target?.Links?.Add(item.Key, item.Value); } } @@ -325,7 +327,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.Callbacks is not null && !target.Callbacks.ContainsKey(item.Key))) { moreStuff = true; - target?.Callbacks?.Add(item); + target?.Callbacks?.Add(item.Key, item.Value); } } @@ -335,7 +337,7 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.Examples is not null && !target.Examples.ContainsKey(item.Key))) { moreStuff = true; - target?.Examples?.Add(item); + target?.Examples?.Add(item.Key, item.Value); } } @@ -345,14 +347,14 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon .Where(item => target?.SecuritySchemes is not null && !target.SecuritySchemes.ContainsKey(item.Key))) { moreStuff = true; - target?.SecuritySchemes?.Add(item); + target?.SecuritySchemes?.Add(item.Key, item.Value); } } return moreStuff; } - private static string ExtractPath(string url, IList? serverList) + private static string ExtractPath(string url, List? serverList) { // if OpenAPI has servers, then see if the url matches one of them var baseUrl = serverList?.Select(s => s.Url?.TrimEnd('/')) @@ -363,7 +365,7 @@ private static string ExtractPath(string url, IList? serverList) : url.Split(new[] { baseUrl }, StringSplitOptions.None)[1]; } - private static void ValidateFilters(IDictionary>? requestUrls, string? operationIds, string? tags) + private static void ValidateFilters(Dictionary>? requestUrls, string? operationIds, string? tags) { if (requestUrls != null && (operationIds != null || tags != null)) { @@ -438,7 +440,7 @@ private static Func GetRequestUrlsPr return (path, operationType, _) => operationTypes.Contains(operationType + path); } - private static List GetOperationTypes(IDictionary openApiOperations, List url, string path) + private static List GetOperationTypes(Dictionary openApiOperations, List url, string path) { // Add the available ops if they are in the postman collection. See path.Value return openApiOperations.Where(ops => url.Contains(ops.Key.ToString().ToUpper())) diff --git a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs index ab1a33e0b..5e4029c4d 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs @@ -21,7 +21,7 @@ public class OpenApiUrlTreeNode /// /// All the subdirectories of a node. /// - public IDictionary Children { get; } = new Dictionary(); + public Dictionary Children { get; } = new Dictionary(); /// /// The relative directory path of the current node from the root node. @@ -31,12 +31,12 @@ public class OpenApiUrlTreeNode /// /// Dictionary of labels and Path Item objects that describe the operations available on a node. /// - public IDictionary PathItems { get; } = new Dictionary(); + public Dictionary PathItems { get; } = new Dictionary(); /// /// A dictionary of key value pairs that contain information about a node. /// - public IDictionary> AdditionalData { get; set; } = new Dictionary>(); + public Dictionary> AdditionalData { get; set; } = new Dictionary>(); /// /// Flag indicating whether a node segment is a path parameter. diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs index aae8527d7..3f6cb1a92 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs @@ -86,7 +86,7 @@ public virtual void Visit(OpenApiLicense license) /// /// Visits list of /// - public virtual void Visit(IList servers) + public virtual void Visit(List servers) { } @@ -107,7 +107,7 @@ public virtual void Visit(OpenApiPaths paths) /// /// Visits Webhooks> /// - public virtual void Visit(IDictionary webhooks) + public virtual void Visit(Dictionary webhooks) { } @@ -128,7 +128,7 @@ public virtual void Visit(OpenApiServerVariable serverVariable) /// /// Visits the operations. /// - public virtual void Visit(IDictionary operations) + public virtual void Visit(Dictionary operations) { } @@ -142,7 +142,7 @@ public virtual void Visit(OpenApiOperation operation) /// /// Visits list of /// - public virtual void Visit(IList parameters) + public virtual void Visit(List parameters) { } @@ -163,14 +163,14 @@ public virtual void Visit(IOpenApiRequestBody requestBody) /// /// Visits headers. /// - public virtual void Visit(IDictionary headers) + public virtual void Visit(Dictionary headers) { } /// /// Visits callbacks. /// - public virtual void Visit(IDictionary callbacks) + public virtual void Visit(Dictionary callbacks) { } @@ -191,7 +191,7 @@ public virtual void Visit(OpenApiResponses response) /// /// Visits media type content. /// - public virtual void Visit(IDictionary content) + public virtual void Visit(Dictionary content) { } @@ -212,7 +212,7 @@ public virtual void Visit(OpenApiEncoding encoding) /// /// Visits the examples. /// - public virtual void Visit(IDictionary examples) + public virtual void Visit(Dictionary examples) { } @@ -240,7 +240,7 @@ public virtual void Visit(IOpenApiSchema schema) /// /// Visits the links. /// - public virtual void Visit(IDictionary links) + public virtual void Visit(Dictionary links) { } @@ -310,21 +310,21 @@ public virtual void Visit(IOpenApiExample example) /// /// Visits list of /// - public virtual void Visit(ISet openApiTags) + public virtual void Visit(HashSet openApiTags) { } /// /// Visits list of /// - public virtual void Visit(ISet openApiTags) + public virtual void Visit(HashSet openApiTags) { } /// /// Visits list of /// - public virtual void Visit(IList openApiSecurityRequirements) + public virtual void Visit(List openApiSecurityRequirements) { } @@ -345,14 +345,14 @@ public virtual void Visit(IOpenApiExtension openApiExtension) /// /// Visits list of /// - public virtual void Visit(IList example) + public virtual void Visit(List example) { } /// /// Visits a dictionary of server variables /// - public virtual void Visit(IDictionary serverVariables) + public virtual void Visit(Dictionary serverVariables) { } @@ -360,7 +360,7 @@ public virtual void Visit(IDictionary serverVaria /// Visits a dictionary of encodings /// /// - public virtual void Visit(IDictionary encodings) + public virtual void Visit(Dictionary encodings) { } diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs index 49ac98079..c0cc15979 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs @@ -62,7 +62,7 @@ public void Walk(OpenApiDocument? doc) /// /// Visits list of and child objects /// - internal void Walk(ISet? tags) + internal void Walk(HashSet? tags) { if (tags == null) { @@ -85,7 +85,7 @@ internal void Walk(ISet? tags) /// /// Visits list of and child objects /// - internal void Walk(ISet? tags) + internal void Walk(HashSet? tags) { if (tags == null) { @@ -283,7 +283,7 @@ internal void Walk(OpenApiPaths paths) /// /// Visits Webhooks and child objects /// - internal void Walk(IDictionary? webhooks) + internal void Walk(Dictionary? webhooks) { if (webhooks == null) { @@ -307,7 +307,7 @@ internal void Walk(IDictionary? webhooks) /// /// Visits list of and child objects /// - internal void Walk(IList? servers) + internal void Walk(List? servers) { if (servers == null) { @@ -489,7 +489,7 @@ internal void Walk(OpenApiServer? server) /// /// Visits dictionary of /// - internal void Walk(IDictionary? serverVariables) + internal void Walk(Dictionary? serverVariables) { if (serverVariables == null) { @@ -566,7 +566,7 @@ internal void Walk(IOpenApiPathItem pathItem, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary? operations) + internal void Walk(Dictionary? operations) { if (operations == null) { @@ -610,7 +610,7 @@ internal void Walk(OpenApiOperation operation) /// /// Visits list of /// - internal void Walk(IList? securityRequirements) + internal void Walk(List? securityRequirements) { if (securityRequirements == null) { @@ -631,7 +631,7 @@ internal void Walk(IList? securityRequirements) /// /// Visits list of /// - internal void Walk(IList? parameters) + internal void Walk(List? parameters) { if (parameters == null) { @@ -748,7 +748,7 @@ internal void Walk(IOpenApiRequestBody? requestBody, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary? headers) + internal void Walk(Dictionary? headers) { if (headers == null) { @@ -770,7 +770,7 @@ internal void Walk(IDictionary? headers) /// /// Visits dictionary of /// - internal void Walk(IDictionary? callbacks) + internal void Walk(Dictionary? callbacks) { if (callbacks == null) { @@ -792,7 +792,7 @@ internal void Walk(IDictionary? callbacks) /// /// Visits dictionary of /// - internal void Walk(IDictionary? content) + internal void Walk(Dictionary? content) { if (content == null) { @@ -832,7 +832,7 @@ internal void Walk(OpenApiMediaType mediaType) /// /// Visits dictionary of /// - internal void Walk(IDictionary? encodings) + internal void Walk(Dictionary? encodings) { if (encodings == null) { @@ -944,7 +944,7 @@ internal void Walk(IOpenApiSchema? schema, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary? examples) + internal void Walk(Dictionary? examples) { if (examples == null) { @@ -1000,7 +1000,7 @@ internal void Walk(IOpenApiExample example, bool isComponent = false) /// /// Visits the list of and child objects /// - internal void Walk(IList examples) + internal void Walk(List examples) { if (examples == null) { @@ -1022,7 +1022,7 @@ internal void Walk(IList examples) /// /// Visits a list of and child objects /// - internal void Walk(IList schemas) + internal void Walk(List schemas) { if (schemas == null) { @@ -1069,7 +1069,7 @@ internal void Walk(OpenApiOAuthFlow oAuthFlow) /// /// Visits dictionary of and child objects /// - internal void Walk(IDictionary? links) + internal void Walk(Dictionary? links) { if (links == null) { @@ -1202,11 +1202,11 @@ internal void Walk(IOpenApiElement element) case IOpenApiCallback e: Walk(e); break; case OpenApiEncoding e: Walk(e); break; case IOpenApiExample e: Walk(e); break; - case IDictionary e: Walk(e); break; + case Dictionary e: Walk(e); break; case OpenApiExternalDocs e: Walk(e); break; case OpenApiHeader e: Walk(e); break; case OpenApiLink e: Walk(e); break; - case IDictionary e: Walk(e); break; + case Dictionary e: Walk(e); break; case OpenApiMediaType e: Walk(e); break; case OpenApiOAuthFlows e: Walk(e); break; case OpenApiOAuthFlow e: Walk(e); break; @@ -1221,7 +1221,7 @@ internal void Walk(IOpenApiElement element) case OpenApiServer e: Walk(e); break; case OpenApiServerVariable e: Walk(e); break; case OpenApiTag e: Walk(e); break; - case ISet e: Walk(e); break; + case HashSet e: Walk(e); break; case IOpenApiExtensible e: Walk(e); break; case IOpenApiExtension e: Walk(e); break; } diff --git a/src/Microsoft.OpenApi/Services/OperationSearch.cs b/src/Microsoft.OpenApi/Services/OperationSearch.cs index ff2de5d2d..53e23f9af 100644 --- a/src/Microsoft.OpenApi/Services/OperationSearch.cs +++ b/src/Microsoft.OpenApi/Services/OperationSearch.cs @@ -21,7 +21,7 @@ public class OperationSearch : OpenApiVisitorBase /// /// A list of operations from the operation search. /// - public IList SearchResults => _searchResults; + public List SearchResults => _searchResults; /// /// The OperationSearch constructor. @@ -59,7 +59,7 @@ public override void Visit(IOpenApiPathItem pathItem) /// Visits list of . /// /// The target list of . - public override void Visit(IList parameters) + public override void Visit(List parameters) { /* The Parameter.Explode property should be true * if Parameter.Style == Form; but OData query params diff --git a/src/Microsoft.OpenApi/Services/SearchResult.cs b/src/Microsoft.OpenApi/Services/SearchResult.cs index 2fea9e03d..32e999e98 100644 --- a/src/Microsoft.OpenApi/Services/SearchResult.cs +++ b/src/Microsoft.OpenApi/Services/SearchResult.cs @@ -25,6 +25,6 @@ public class SearchResult /// /// Parameters object /// - public IList? Parameters { get; set; } + public List? Parameters { get; set; } } } diff --git a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs index 54bd92deb..850d23635 100644 --- a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs +++ b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs @@ -18,8 +18,8 @@ namespace Microsoft.OpenApi.Validations public class OpenApiValidator : OpenApiVisitorBase, IValidationContext { private readonly ValidationRuleSet _ruleSet; - private readonly IList _errors = new List(); - private readonly IList _warnings = new List(); + private readonly List _errors = []; + private readonly List _warnings = []; /// /// Create a visitor that will validate an OpenAPIDocument @@ -120,7 +120,7 @@ public void AddWarning(OpenApiValidatorWarning warning) public override void Visit(IOpenApiExtension openApiExtension) => Validate(openApiExtension, openApiExtension.GetType()); /// - public override void Visit(IList example) => Validate(example, example.GetType()); + public override void Visit(List example) => Validate(example, example.GetType()); /// public override void Visit(IOpenApiPathItem pathItem) => Validate(pathItem); @@ -149,21 +149,21 @@ public void AddWarning(OpenApiValidatorWarning warning) /// public override void Visit(OpenApiOperation operation) => Validate(operation); /// - public override void Visit(IDictionary operations) => Validate(operations, operations.GetType()); + public override void Visit(Dictionary operations) => Validate(operations, operations.GetType()); /// - public override void Visit(IDictionary headers) => Validate(headers, headers.GetType()); + public override void Visit(Dictionary headers) => Validate(headers, headers.GetType()); /// - public override void Visit(IDictionary callbacks) => Validate(callbacks, callbacks.GetType()); + public override void Visit(Dictionary callbacks) => Validate(callbacks, callbacks.GetType()); /// - public override void Visit(IDictionary content) => Validate(content, content.GetType()); + public override void Visit(Dictionary content) => Validate(content, content.GetType()); /// - public override void Visit(IDictionary examples) => Validate(examples, examples.GetType()); + public override void Visit(Dictionary examples) => Validate(examples, examples.GetType()); /// - public override void Visit(IDictionary links) => Validate(links, links.GetType()); + public override void Visit(Dictionary links) => Validate(links, links.GetType()); /// - public override void Visit(IDictionary serverVariables) => Validate(serverVariables, serverVariables.GetType()); + public override void Visit(Dictionary serverVariables) => Validate(serverVariables, serverVariables.GetType()); /// - public override void Visit(IDictionary encodings) => Validate(encodings, encodings.GetType()); + public override void Visit(Dictionary encodings) => Validate(encodings, encodings.GetType()); private void Validate(T item) { diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs index e31dc1e07..ba8713910 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiContactRules.cs @@ -21,13 +21,10 @@ public static class OpenApiContactRules (context, item) => { context.Enter("email"); - if (item is {Email: not null}) + if (item is {Email: not null} && !item.Email.IsEmailAddress()) { - if (!item.Email.IsEmailAddress()) - { - context.CreateError(nameof(EmailMustBeEmailFormat), - String.Format(SRResource.Validation_StringMustBeEmailAddress, item.Email)); - } + context.CreateError(nameof(EmailMustBeEmailFormat), + String.Format(SRResource.Validation_StringMustBeEmailAddress, item.Email)); } context.Exit(); }); diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs index 9853acb37..eba253df6 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiExtensionRules.cs @@ -29,9 +29,9 @@ public static class OpenApiExtensibleRules { context.CreateError(nameof(ExtensionNameMustStartWithXDash), string.Format(SRResource.Validation_ExtensionNameMustBeginWithXDash, extensible, context.PathString)); - } - context.Exit(); - } + } + } + context.Exit(); }); } } diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs index 70dc7396a..34d84b796 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiNonDefaultRules.cs @@ -90,7 +90,7 @@ public static class OpenApiNonDefaultRules private static void ValidateMismatchedDataType(IValidationContext context, string ruleName, JsonNode? example, - IDictionary? examples, + Dictionary? examples, IOpenApiSchema? schema) { // example diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs index 9884d54dd..808124f01 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiSchemaRules.cs @@ -50,7 +50,7 @@ public static bool ValidateChildSchemaAgainstDiscriminator(IOpenApiSchema schema { if (discriminatorName is not null) { - if (!schema.Required?.Contains(discriminatorName) ?? false) + if (schema.Required is null || !schema.Required.Contains(discriminatorName)) { // recursively check nested schema.OneOf, schema.AnyOf or schema.AllOf and their required fields for the discriminator if (schema.OneOf?.Count != 0) @@ -83,7 +83,7 @@ public static bool ValidateChildSchemaAgainstDiscriminator(IOpenApiSchema schema /// between other schemas which may satisfy the payload description. /// The child schema. /// - public static bool TraverseSchemaElements(string discriminatorName, IList? childSchema) + public static bool TraverseSchemaElements(string discriminatorName, List? childSchema) { if (childSchema is not null) { diff --git a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs index d4ffc5429..375485058 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/OpenApiServerRules.cs @@ -36,9 +36,9 @@ public static class OpenApiServerRules context.Enter(variable.Key); ValidateServerVariableRequiredFields(context, variable.Key, variable.Value); context.Exit(); - } - context.Exit(); - } + } + } + context.Exit(); }); // add more rules diff --git a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs index 1b4896d3a..a19ba82c7 100644 --- a/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs +++ b/src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs @@ -85,13 +85,13 @@ public static void ValidateDataTypeMismatch( return; } - foreach (var kvp in anyObject) + foreach (var key in from kvp in anyObject + let key = kvp.Key + select key) { - var key = kvp.Key; context.Enter(key); - if (schema.Properties != null && - schema.Properties.TryGetValue(key, out var property)) + schema.Properties.TryGetValue(key, out var property)) { ValidateDataTypeMismatch(context, ruleName, anyObject[key], property); } diff --git a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs index d09d9b566..943b88e6b 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Validations /// public sealed class ValidationRuleSet { - private Dictionary> _rulesDictionary = new(); + private Dictionary> _rulesDictionary = new(); private static ValidationRuleSet? _defaultRuleSet; @@ -26,7 +26,7 @@ public sealed class ValidationRuleSet /// /// Gets the rules in this rule set. /// - public IList Rules => _rulesDictionary.Values.SelectMany(v => v).ToList(); + public List Rules => _rulesDictionary.Values.SelectMany(v => v).ToList(); /// /// Gets the number of elements contained in this rule set. @@ -45,7 +45,7 @@ public ValidationRuleSet() /// /// The type that is to be validated /// Either the rules related to the type, or an empty list. - public IList FindRules(Type type) + public List FindRules(Type type) { _rulesDictionary.TryGetValue(type, out var results); return results ?? _emptyRules; @@ -85,7 +85,7 @@ public static ValidationRuleSet GetEmptyRuleSet() /// The rule set to add validation rules to. /// The validation rules to be added to the rules set. /// Throws a null argument exception if the arguments are null. - public static void AddValidationRules(ValidationRuleSet ruleSet, IDictionary> rules) + public static void AddValidationRules(ValidationRuleSet ruleSet, Dictionary> rules) { if (ruleSet == null || rules == null) { @@ -119,7 +119,7 @@ public ValidationRuleSet(ValidationRuleSet ruleSet) /// Initializes a new instance of the class. /// /// Rules to be contained in this ruleset. - public ValidationRuleSet(IDictionary> rules) + public ValidationRuleSet(Dictionary> rules) { if (rules == null) { @@ -137,7 +137,7 @@ public ValidationRuleSet(IDictionary> rules) /// /// The key for the rule. /// The list of rules. - public void Add(Type key, IList rules) + public void Add(Type key, List rules) { foreach (var rule in rules) { @@ -155,7 +155,7 @@ public void Add(Type key, ValidationRule rule) { if (!_rulesDictionary.ContainsKey(key)) { - _rulesDictionary[key] = new List(); + _rulesDictionary[key] = []; } if (_rulesDictionary[key].Contains(rule)) @@ -199,7 +199,7 @@ public bool Remove(Type key) /// Name of the rule. public void Remove(string ruleName) { - foreach (KeyValuePair> rule in _rulesDictionary) + foreach (KeyValuePair> rule in _rulesDictionary) { _rulesDictionary[rule.Key] = rule.Value.Where(vr => !vr.Name.Equals(ruleName, StringComparison.Ordinal)).ToList(); } @@ -216,7 +216,7 @@ public void Remove(string ruleName) /// true if the rule is successfully removed; otherwise, false. public bool Remove(Type key, ValidationRule rule) { - if (_rulesDictionary.TryGetValue(key, out IList? validationRules)) + if (_rulesDictionary.TryGetValue(key, out List? validationRules)) { return validationRules.Remove(rule); } @@ -260,7 +260,7 @@ public bool ContainsKey(Type key) /// public bool Contains(Type key, ValidationRule rule) { - return _rulesDictionary.TryGetValue(key, out IList? validationRules) && validationRules.Contains(rule); + return _rulesDictionary.TryGetValue(key, out List? validationRules) && validationRules.Contains(rule); } /// @@ -271,7 +271,7 @@ public bool Contains(Type key, ValidationRule rule) /// key is found; otherwise, an empty object. /// This parameter is passed uninitialized. /// true if the specified key has rules. - public bool TryGetValue(Type key, out IList? rules) + public bool TryGetValue(Type key, out List? rules) { return _rulesDictionary.TryGetValue(key, out rules); } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs index eee8068a9..222d7a24e 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs @@ -22,7 +22,7 @@ public static class OpenApiWriterAnyExtensions /// The Open API writer. /// The specification extensions. /// Version of the OpenAPI specification that that will be output. - public static void WriteExtensions(this IOpenApiWriter writer, IDictionary? extensions, OpenApiSpecVersion specVersion) + public static void WriteExtensions(this IOpenApiWriter writer, Dictionary? extensions, OpenApiSpecVersion specVersion) { Utils.CheckArgumentNull(writer); diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs index 3df27f6d7..31f60d0fd 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs @@ -246,7 +246,7 @@ public static void WriteRequiredCollection( public static void WriteRequiredMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { writer.WriteMapInternal(name, elements, action); @@ -262,7 +262,7 @@ public static void WriteRequiredMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -281,7 +281,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -300,7 +300,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { if (elements != null && elements.Any()) @@ -319,8 +319,8 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary>? elements, - Action> action) + Dictionary>? elements, + Action> action) { if (elements != null && elements.Any()) { @@ -339,7 +339,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) where T : IOpenApiElement { @@ -360,7 +360,7 @@ public static void WriteOptionalMap( public static void WriteOptionalMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) where T : IOpenApiElement { @@ -381,7 +381,7 @@ public static void WriteOptionalMap( public static void WriteRequiredMap( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) where T : IOpenApiElement { @@ -419,7 +419,7 @@ private static void WriteCollectionInternal( private static void WriteMapInternal( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { WriteMapInternal(writer, name, elements, (w, _, s) => action(w, s)); @@ -428,7 +428,7 @@ private static void WriteMapInternal( private static void WriteMapInternal( this IOpenApiWriter writer, string name, - IDictionary? elements, + Dictionary? elements, Action action) { Utils.CheckArgumentNull(action); diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs index 92cfae013..7b3cd338e 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs @@ -32,11 +32,11 @@ public void FormatOperationIdsInOpenAPIDocument(string operationId, string expec var openApiDocument = new OpenApiDocument { Info = new() { Title = "Test", Version = "1.0" }, - Servers = new List { new() { Url = "https://localhost/" } }, + Servers = [new() { Url = "https://localhost/" }], Paths = new() { { path, new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { operationType, new() { OperationId = operationId } } } @@ -96,7 +96,7 @@ public void ResolveFunctionParameters() var walker = new OpenApiWalker(powerShellFormatter); walker.Walk(openApiDocument); - var idsParameter = openApiDocument.Paths["/foo"].Operations?[HttpMethod.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault(); + var idsParameter = openApiDocument.Paths["/foo"].Operations?[HttpMethod.Get].Parameters?.FirstOrDefault(static p => p.Name == "ids"); // Assert Assert.Null(idsParameter?.Content); @@ -109,11 +109,11 @@ private static OpenApiDocument GetSampleOpenApiDocument() return new() { Info = new() { Title = "Test", Version = "1.0" }, - Servers = new List { new() { Url = "https://localhost/" } }, + Servers = [new() { Url = "https://localhost/" }], Paths = new() { { "/foo", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new() @@ -125,7 +125,7 @@ private static OpenApiDocument GetSampleOpenApiDocument() { Name = "ids", In = ParameterLocation.Query, - Content = new Dictionary + Content = new() { { "application/json", @@ -144,7 +144,7 @@ private static OpenApiDocument GetSampleOpenApiDocument() } } ], - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-operation-type", new OpenApiAny("function") @@ -158,32 +158,32 @@ private static OpenApiDocument GetSampleOpenApiDocument() }, Components = new() { - Schemas = new Dictionary + Schemas = new() { { "TestSchema", new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { { "averageAudioDegradation", new OpenApiSchema { - AnyOf = new List - { + AnyOf = + [ new OpenApiSchema() { Type = JsonSchemaType.Number | JsonSchemaType.Null }, new OpenApiSchema() { Type = JsonSchemaType.String } - }, + ], Format = "float", } }, { "defaultPrice", new OpenApiSchema { - OneOf = new List - { + OneOf = + [ new OpenApiSchema() { Type = JsonSchemaType.Number, Format = "double" }, new OpenApiSchema() { Type = JsonSchemaType.String } - } + ] } } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs index 7702c56c1..e617d3b3c 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs @@ -79,11 +79,11 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() var openApiDocument = new OpenApiDocument { Info = new() { Title = "Test", Version = "1.0" }, - Servers = new List { new() { Url = "https://localhost/" } }, + Servers = [new() { Url = "https://localhost/" }], Paths = new() { {"/foo", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new() }, { HttpMethod.Patch, new() }, @@ -97,7 +97,7 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() // Given a set of RequestUrls var requestUrls = new Dictionary> { - {"/foo", new List {"GET","POST"}} + {"/foo", ["GET","POST"]} }; // When @@ -116,12 +116,12 @@ public void CreateFilteredDocumentUsingPredicateFromRequestUrl() var openApiDocument = new OpenApiDocument { Info = new() { Title = "Test", Version = "1.0" }, - Servers = new List { new() { Url = "https://localhost/" } }, + Servers = [new() { Url = "https://localhost/" }], Paths = new() { ["/test/{id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new() }, { HttpMethod.Patch, new() } @@ -147,7 +147,7 @@ public void CreateFilteredDocumentUsingPredicateFromRequestUrl() var requestUrls = new Dictionary> { - {"/test/{id}", new List {"GET","PATCH"}} + {"/test/{id}",["GET","PATCH"]} }; // Act @@ -302,7 +302,7 @@ public void ReturnsPathParametersOnSlicingBasedOnOperationIdsOrTags(string? oper // Assert foreach (var pathItem in subsetOpenApiDocument.Paths) { - Assert.True(pathItem.Value.Parameters!.Any()); + Assert.True(pathItem.Value.Parameters!.Count != 0); Assert.Single(pathItem.Value.Parameters!); } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index f39e87c69..7e5b4de3c 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -45,7 +45,7 @@ public void CreateFilteredDocumentOnMinimalOpenApi() { ["/test"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation() } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs index 71768bfbe..421cecdd7 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs @@ -40,18 +40,18 @@ public static OpenApiDocument CreateOpenApiDocument() Title = "People", Version = "v1.0" }, - Servers = new List - { + Servers = + [ new() { Url = "https://graph.microsoft.com/v1.0" } - }, + ], Paths = new() { ["/"] = new OpenApiPathItem() // root path { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -72,35 +72,33 @@ public static OpenApiDocument CreateOpenApiDocument() }, [getTeamsActivityByPeriodPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation { OperationId = "reports.getTeamsUserActivityCounts", Summary = "Invoke function getTeamsUserActivityUserCounts", - Parameters = new List - { + Parameters = + [ + new OpenApiParameter() { - new OpenApiParameter() + Name = "period", + In = ParameterLocation.Path, + Required = true, + Schema = new OpenApiSchema() { - Name = "period", - In = ParameterLocation.Path, - Required = true, - Schema = new OpenApiSchema() - { - Type = JsonSchemaType.String - } + Type = JsonSchemaType.String } } - }, + ], Responses = new() { { "200", new OpenApiResponse() { Description = "Success", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -119,53 +117,49 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Parameters = new List - { + Parameters = + [ + new OpenApiParameter() { - new OpenApiParameter() + Name = "period", + In = ParameterLocation.Path, + Required = true, + Schema = new OpenApiSchema() { - Name = "period", - In = ParameterLocation.Path, - Required = true, - Schema = new OpenApiSchema() - { - Type = JsonSchemaType.String - } + Type = JsonSchemaType.String } } - } + ] }, [getTeamsActivityByDatePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation { OperationId = "reports.getTeamsUserActivityUserDetail-a3f1", Summary = "Invoke function getTeamsUserActivityUserDetail", - Parameters = new List - { + Parameters = + [ + new OpenApiParameter() { - new OpenApiParameter() + Name = "period", + In = ParameterLocation.Path, + Required = true, + Schema = new OpenApiSchema() { - Name = "period", - In = ParameterLocation.Path, - Required = true, - Schema = new OpenApiSchema() - { - Type = JsonSchemaType.String - } + Type = JsonSchemaType.String } } - }, + ], Responses = new() { { "200", new OpenApiResponse() { Description = "Success", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -184,8 +178,8 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "period", @@ -196,11 +190,11 @@ public static OpenApiDocument CreateOpenApiDocument() Type = JsonSchemaType.String } } - } + ] }, [usersPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -213,7 +207,7 @@ public static OpenApiDocument CreateOpenApiDocument() "200", new OpenApiResponse() { Description = "Retrieved entities", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -223,7 +217,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Title = "Collection of user", Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { { "value", @@ -246,7 +240,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [usersByIdPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -259,7 +253,7 @@ public static OpenApiDocument CreateOpenApiDocument() "200", new OpenApiResponse() { Description = "Retrieved entity", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -293,7 +287,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [messagesByIdPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -301,8 +295,8 @@ public static OpenApiDocument CreateOpenApiDocument() OperationId = "users.GetMessages", Summary = "Get messages from users", Description = "The messages in a mailbox or folder. Read-only. Nullable.", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "$select", @@ -315,14 +309,14 @@ public static OpenApiDocument CreateOpenApiDocument() } // missing explode parameter } - }, + ], Responses = new() { { "200", new OpenApiResponse() { Description = "Retrieved navigation property", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -340,7 +334,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [administrativeUnitRestorePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Post, new OpenApiOperation @@ -369,7 +363,7 @@ public static OpenApiDocument CreateOpenApiDocument() "200", new OpenApiResponse() { Description = "Success", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -391,7 +385,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [logoPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Put, new OpenApiOperation @@ -413,7 +407,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [securityProfilesPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -426,7 +420,7 @@ public static OpenApiDocument CreateOpenApiDocument() "200", new OpenApiResponse() { Description = "Retrieved navigation property", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -436,7 +430,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Title = "Collection of hostSecurityProfile", Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { { "value", @@ -459,15 +453,15 @@ public static OpenApiDocument CreateOpenApiDocument() }, [communicationsCallsKeepAlivePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Post, new OpenApiOperation { OperationId = "communications.calls.call.keepAlive", Summary = "Invoke action keepAlive", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "call-id", @@ -478,14 +472,14 @@ public static OpenApiDocument CreateOpenApiDocument() { Type = JsonSchemaType.String }, - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-key-type", new OpenApiAny("call") } } } - }, + ], Responses = new() { { @@ -495,7 +489,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-operation-type", new OpenApiAny("action") @@ -507,15 +501,15 @@ public static OpenApiDocument CreateOpenApiDocument() }, [eventsDeltaPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation { OperationId = "groups.group.events.event.calendar.events.delta", Summary = "Invoke function delta", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "group-id", @@ -526,7 +520,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Type = JsonSchemaType.String }, - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-key-type", new OpenApiAny("group") @@ -543,21 +537,21 @@ public static OpenApiDocument CreateOpenApiDocument() { Type = JsonSchemaType.String }, - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-key-type", new OpenApiAny("event") } } } - }, + ], Responses = new() { { "200", new OpenApiResponse() { Description = "Success", - Content = new Dictionary + Content = new() { { applicationJsonMediaType, @@ -565,7 +559,7 @@ public static OpenApiDocument CreateOpenApiDocument() { Schema = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { { "value", @@ -582,7 +576,7 @@ public static OpenApiDocument CreateOpenApiDocument() } } }, - Extensions = new Dictionary + Extensions = new() { { "x-ms-docs-operation-type", new OpenApiAny("function") @@ -594,7 +588,7 @@ public static OpenApiDocument CreateOpenApiDocument() }, [refPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -608,14 +602,14 @@ public static OpenApiDocument CreateOpenApiDocument() }, Components = new() { - Schemas = new Dictionary + Schemas = new() { { "microsoft.graph.networkInterface", new OpenApiSchema { Title = "networkInterface", Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { { "description", new OpenApiSchema diff --git a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs index d32c9b46b..4336a29f8 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs @@ -72,7 +72,7 @@ public async Task LoadResponseReference() new OpenApiResponse { Description = "Entity not found.", - Content = new Dictionary + Content = new() { ["application/json"] = new() } @@ -89,7 +89,7 @@ public async Task LoadResponseAndSchemaReference() var expected = new OpenApiResponse { Description = "General Error", - Content = + Content = new() { ["application/json"] = new() { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index 6bf41959c..d6daa59d8 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -76,7 +76,7 @@ public async Task ShouldParseProducesInAnyOrder() var okSchema = new OpenApiSchema { - Properties = new Dictionary + Properties = new() { { "id", new OpenApiSchema { @@ -89,7 +89,7 @@ public async Task ShouldParseProducesInAnyOrder() var errorSchema = new OpenApiSchema { - Properties = new Dictionary + Properties = new() { { "code", new OpenApiSchema { @@ -132,17 +132,17 @@ public async Task ShouldParseProducesInAnyOrder() Version = "1.0.0" }, Servers = - { + [ new OpenApiServer { Url = "https://" } - }, + ], Paths = new() { ["/items"] = new OpenApiPathItem() { - Operations = + Operations = new() { [HttpMethod.Get] = new() { @@ -151,7 +151,7 @@ public async Task ShouldParseProducesInAnyOrder() ["200"] = new OpenApiResponse() { Description = "An OK response", - Content = + Content = new() { ["application/json"] = okMediaType, ["application/xml"] = okMediaType, @@ -160,7 +160,7 @@ public async Task ShouldParseProducesInAnyOrder() ["default"] = new OpenApiResponse() { Description = "An error response", - Content = + Content = new() { ["application/json"] = errorMediaType, ["application/xml"] = errorMediaType @@ -175,7 +175,7 @@ public async Task ShouldParseProducesInAnyOrder() ["200"] = new OpenApiResponse() { Description = "An OK response", - Content = + Content = new() { ["html/text"] = okMediaType } @@ -183,7 +183,7 @@ public async Task ShouldParseProducesInAnyOrder() ["default"] = new OpenApiResponse() { Description = "An error response", - Content = + Content = new() { ["html/text"] = errorMediaType } @@ -197,7 +197,7 @@ public async Task ShouldParseProducesInAnyOrder() ["200"] = new OpenApiResponse() { Description = "An OK response", - Content = + Content = new() { ["application/json"] = okMediaType, ["application/xml"] = okMediaType, @@ -206,7 +206,7 @@ public async Task ShouldParseProducesInAnyOrder() ["default"] = new OpenApiResponse() { Description = "An error response", - Content = + Content = new() { ["application/json"] = errorMediaType, ["application/xml"] = errorMediaType @@ -219,7 +219,7 @@ public async Task ShouldParseProducesInAnyOrder() }, Components = new() { - Schemas = + Schemas = new() { ["Item"] = okSchema, ["Error"] = errorSchema diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs index 1b1187a42..86ebfcab2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs @@ -68,11 +68,11 @@ public void ParseHeaderWithEnumShouldSucceed() Type = JsonSchemaType.Number, Format = "float", Enum = - { + [ new OpenApiAny(7).Node, new OpenApiAny(8).Node, new OpenApiAny(9).Node - } + ] } }, options => options.IgnoringCyclicReferences() .Excluding((IMemberInfo memberInfo) => diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs index cd62c27be..3d40535c6 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs @@ -10,6 +10,7 @@ using FluentAssertions; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -51,7 +52,7 @@ public class OpenApiOperationTests ["200"] = new OpenApiResponse { Description = "Pet updated.", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType(), ["application/xml"] = new OpenApiMediaType() @@ -83,7 +84,7 @@ public class OpenApiOperationTests { Description = "Pet to update with", Required = true, - Content = + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -93,7 +94,8 @@ public class OpenApiOperationTests } } }, - Extensions = { + Extensions = new() + { [OpenApiConstants.BodyName] = new OpenApiAny("petObject") } }, @@ -102,7 +104,7 @@ public class OpenApiOperationTests ["200"] = new OpenApiResponse { Description = "Pet updated.", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType(), ["application/xml"] = new OpenApiMediaType() @@ -111,7 +113,7 @@ public class OpenApiOperationTests ["405"] = new OpenApiResponse { Description = "Invalid input", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType(), ["application/xml"] = new OpenApiMediaType() @@ -213,7 +215,7 @@ public void ParseOperationWithResponseExamplesShouldSucceed() { "200", new OpenApiResponse() { Description = "An array of float response", - Content = + Content = new() { ["application/json"] = new OpenApiMediaType() { @@ -524,7 +526,7 @@ public async Task SerializesBodyReferencesWorks() }; openApiDocument.Paths.Add("/users", new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Post] = operation } @@ -532,7 +534,7 @@ public async Task SerializesBodyReferencesWorks() openApiDocument.AddComponent("UserRequest", new OpenApiRequestBody { Description = "User creation request body", - Content = + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -543,7 +545,7 @@ public async Task SerializesBodyReferencesWorks() openApiDocument.AddComponent("UserSchema", new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = + Properties = new Dictionary { ["name"] = new OpenApiSchema { @@ -624,7 +626,7 @@ public void DeduplicatesTagReferences() Description = "", OperationId = "loginUser", Parameters = - { + [ new OpenApiParameter { Name = "password", @@ -636,7 +638,7 @@ public void DeduplicatesTagReferences() Type = JsonSchemaType.String } } - } + ] }; using var textWriter = new StringWriter(); var writer = new OpenApiJsonWriter(textWriter); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs index b20c27761..6e8685c4b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs @@ -267,11 +267,11 @@ public void ParseParameterWithEnumShouldSucceed() Type = JsonSchemaType.Number, Format = "float", Enum = - { - new OpenApiAny(7).Node, - new OpenApiAny(8).Node, - new OpenApiAny(9).Node - } + [ + new OpenApiAny(7).Node, + new OpenApiAny(8).Node, + new OpenApiAny(9).Node + ] } }; diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs index b3ebdc3dc..7079b4b5a 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs @@ -7,8 +7,10 @@ using System.Linq; using System.Net.Http; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Reader.ParseNodes; using Microsoft.OpenApi.Reader.V2; +using Microsoft.OpenApi.Writers; using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V2Tests @@ -39,7 +41,7 @@ public class OpenApiPathItemTests Style = ParameterStyle.Simple } ], - Operations = + Operations = new() { [HttpMethod.Put] = new() { @@ -62,14 +64,14 @@ public class OpenApiPathItemTests ], RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/x-www-form-urlencoded"] = new() { Schema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -93,7 +95,7 @@ public class OpenApiPathItemTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -119,7 +121,7 @@ public class OpenApiPathItemTests ["200"] = new OpenApiResponse() { Description = "Pet updated.", - Content = new Dictionary + Content = new() { ["application/json"] = new(), ["application/xml"] = new() @@ -128,7 +130,7 @@ public class OpenApiPathItemTests ["405"] = new OpenApiResponse() { Description = "Invalid input", - Content = new Dictionary + Content = new() { ["application/json"] = new(), ["application/xml"] = new() @@ -168,14 +170,14 @@ public class OpenApiPathItemTests ], RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/x-www-form-urlencoded"] = new() { Schema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -204,7 +206,7 @@ public class OpenApiPathItemTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -222,10 +224,10 @@ public class OpenApiPathItemTests Type = JsonSchemaType.String } }, - Required = new HashSet - { + Required = + [ "name" - } + ] } } } @@ -235,7 +237,7 @@ public class OpenApiPathItemTests ["200"] = new OpenApiResponse() { Description = "Pet updated.", - Content = new Dictionary + Content = new() { ["application/json"] = new(), ["application/xml"] = new() diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs index 781b272e1..68f41271a 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs @@ -85,12 +85,12 @@ public void ParseSchemaWithEnumShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Enum = new List - { + Enum = + [ new OpenApiAny(7).Node, new OpenApiAny(8).Node, new OpenApiAny(9).Node - } + ] }; schema.Should().BeEquivalentTo(expected, options => @@ -109,7 +109,7 @@ public void PropertiesReferenceShouldWork() var targetSchema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["prop1"] = new OpenApiSchema() { @@ -117,12 +117,15 @@ public void PropertiesReferenceShouldWork() } } }; - workingDocument.Components.Schemas.Add(referenceId, targetSchema); + workingDocument.Components.Schemas = new() + { + [referenceId] = targetSchema + }; workingDocument.Workspace.RegisterComponents(workingDocument); var referenceSchema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["propA"] = new OpenApiSchemaReference(referenceId, workingDocument), } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs index bdac6ac26..86d7943fb 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSecuritySchemeTests.cs @@ -2,8 +2,8 @@ // Licensed under the MIT license. using System; +using System.Collections.Generic; using System.IO; -using System.Linq; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader; using Microsoft.OpenApi.Reader.ParseNodes; @@ -95,7 +95,7 @@ public void ParseOAuth2ImplicitSecuritySchemeShouldSucceed() Implicit = new() { AuthorizationUrl = new("http://swagger.io/api/oauth/dialog"), - Scopes = + Scopes = new Dictionary { ["write:pets"] = "modify pets in your account", ["read:pets"] = "read your pets" @@ -130,7 +130,7 @@ public void ParseOAuth2PasswordSecuritySchemeShouldSucceed() Password = new OpenApiOAuthFlow { AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), - Scopes = + Scopes = new Dictionary { ["write:pets"] = "modify pets in your account", ["read:pets"] = "read your pets" @@ -165,7 +165,7 @@ public void ParseOAuth2ApplicationSecuritySchemeShouldSucceed() ClientCredentials = new OpenApiOAuthFlow { AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), - Scopes = + Scopes = new Dictionary { ["write:pets"] = "modify pets in your account", ["read:pets"] = "read your pets" @@ -201,7 +201,7 @@ public void ParseOAuth2AccessCodeSecuritySchemeShouldSucceed() AuthorizationCode = new OpenApiOAuthFlow { AuthorizationUrl = new Uri("http://swagger.io/api/oauth/dialog"), - Scopes = + Scopes = new Dictionary { ["write:pets"] = "modify pets in your account", ["read:pets"] = "read your pets" @@ -216,7 +216,7 @@ static YamlDocument LoadYamlDocument(Stream input) using var reader = new StreamReader(input); var yamlStream = new YamlStream(); yamlStream.Load(reader); - return yamlStream.Documents.First(); + return yamlStream.Documents[0]; } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs index 167d59cc7..fa99dcd1b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs @@ -32,7 +32,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() var components = new OpenApiComponents { - Schemas = + Schemas = new() { ["petSchema"] = new OpenApiSchema() { @@ -42,11 +42,11 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() "id", "name" }, - DependentRequired = new Dictionary> + DependentRequired = new Dictionary> { { "tag", new HashSet { "category" } } }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -74,11 +74,11 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() { "name" }, - DependentRequired = new Dictionary> + DependentRequired = new Dictionary> { { "tag", new HashSet { "category" } } }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -113,7 +113,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() { ["pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -154,7 +154,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -182,7 +182,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() { Description = "Information about a new pet in the system", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -195,7 +195,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() ["200"] = new OpenApiResponse { Description = "Return a 200 status to indicate that the data was received successfully", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -224,7 +224,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() var components = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["petSchema"] = new OpenApiSchema() { @@ -234,11 +234,11 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() "id", "name" }, - DependentRequired = new Dictionary> + DependentRequired = new Dictionary> { { "tag", new HashSet { "category" } } }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -266,11 +266,11 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() { "name" }, - DependentRequired = new Dictionary> + DependentRequired = new Dictionary> { { "tag", new HashSet { "category" } } }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -303,48 +303,48 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() { ["pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", Parameters = - [ - new OpenApiParameter + [ + new OpenApiParameter + { + Name = "tags", + In = ParameterLocation.Query, + Description = "tags to filter by", + Required = false, + Schema = new OpenApiSchema() { - Name = "tags", - In = ParameterLocation.Query, - Description = "tags to filter by", - Required = false, - Schema = new OpenApiSchema() + Type = JsonSchemaType.Array, + Items = new OpenApiSchema() { - Type = JsonSchemaType.Array, - Items = new OpenApiSchema() - { - Type = JsonSchemaType.String - } + Type = JsonSchemaType.String } - }, - new OpenApiParameter + } + }, + new OpenApiParameter + { + Name = "limit", + In = ParameterLocation.Query, + Description = "maximum number of results to return", + Required = false, + Schema = new OpenApiSchema() { - Name = "limit", - In = ParameterLocation.Query, - Description = "maximum number of results to return", - Required = false, - Schema = new OpenApiSchema() - { - Type = JsonSchemaType.Integer, - Format = "int32" - } + Type = JsonSchemaType.Integer, + Format = "int32" } - ], + } + ], Responses = new OpenApiResponses { ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -372,7 +372,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() { Description = "Information about a new pet in the system", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -385,7 +385,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() ["200"] = new OpenApiResponse { Description = "Return a 200 status to indicate that the data was received successfully", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -447,7 +447,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks() var expectedSchema = new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["prop1"] = new OpenApiSchema { @@ -462,7 +462,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks() Type = JsonSchemaType.String } }, - PatternProperties = new Dictionary + PatternProperties = new() { ["^x-.*$"] = new OpenApiSchema { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs index 838ecbff2..9ccb8d0ee 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs @@ -41,7 +41,7 @@ public async Task ParseBasicV31SchemaShouldSucceed() Schema = new Uri("https://json-schema.org/draft/2020-12/schema"), Description = "A representation of a person, company, organization, or place", Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["fruits"] = new OpenApiSchema { @@ -66,11 +66,11 @@ public async Task ParseBasicV31SchemaShouldSucceed() "veggieName", "veggieLike" }, - DependentRequired = new Dictionary> + DependentRequired = new Dictionary> { { "veggieType", new HashSet { "veggieColor", "veggieSize" } } }, - Properties = new Dictionary + Properties = new() { ["veggieName"] = new OpenApiSchema { @@ -181,7 +181,7 @@ public async Task ParseV31SchemaShouldSucceed() var expectedSchema = new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["one"] = new OpenApiSchema() { @@ -205,7 +205,7 @@ public async Task ParseAdvancedV31SchemaShouldSucceed() var expectedSchema = new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["one"] = new OpenApiSchema() { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs index 93b5677e7..2b131f263 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Reader; using Xunit; @@ -27,19 +29,19 @@ public async Task ParseBasicCallbackShouldSucceed() Assert.Equivalent( new OpenApiCallback { - PathItems = + PathItems = new Dictionary { [RuntimeExpression.Build("$request.body#/url")] = new OpenApiPathItem { - Operations = + Operations = new Dictionary { [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { - Content = + Content = new Dictionary { ["application/json"] = null } @@ -81,12 +83,13 @@ public async Task ParseCallbackWithReferenceShouldSucceed() PathItems = { [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { - Operations = { + Operations = new Dictionary + { [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { - Content = + Content = new Dictionary { ["application/json"] = new OpenApiMediaType { @@ -131,12 +134,13 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() PathItems = { [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { - Operations = { + Operations = new Dictionary + { [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { - Content = + Content = new Dictionary { ["application/json"] = new OpenApiMediaType { @@ -163,16 +167,17 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() Assert.Equivalent( new OpenApiCallback { - PathItems = + PathItems = new Dictionary { [RuntimeExpression.Build("/simplePath")]= new OpenApiPathItem { - Operations = { + Operations = new Dictionary + { [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { Description = "Callback 2", - Content = + Content = new Dictionary { ["application/json"] = new OpenApiMediaType { @@ -199,15 +204,16 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() Assert.Equivalent( new OpenApiCallback { - PathItems = + PathItems = new Dictionary { [RuntimeExpression.Build(@"http://example.com?transactionId={$request.body#/id}&email={$request.body#/email}")] = new OpenApiPathItem { - Operations = { + Operations = new Dictionary + { [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { - Content = + Content = new Dictionary { ["application/xml"] = new OpenApiMediaType { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDiscriminatorTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDiscriminatorTests.cs index f1b047f08..f0eb50953 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDiscriminatorTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDiscriminatorTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.OpenApi.Models; @@ -35,8 +36,8 @@ public async Task ParseBasicDiscriminatorShouldSucceed() new OpenApiDiscriminator { PropertyName = "pet_type", - Mapping = - { + Mapping = new Dictionary + { ["puppy"] = new OpenApiSchemaReference("Dog", openApiDocument), ["kitten"] = new OpenApiSchemaReference("Cat" , openApiDocument, "https://gigantic-server.com/schemas/animals.json"), ["monster"] = new OpenApiSchemaReference("schema.json" , openApiDocument, "https://gigantic-server.com/schemas/Monster/schema.json") diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index bc17c02fb..d6b393404 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -112,7 +112,7 @@ public async Task ParseBasicDocumentWithMultipleServersShouldSucceed() Version = "0.9.1", }, Servers = - { + [ new OpenApiServer { Url = new Uri("http://www.example.org/api").ToString(), @@ -123,7 +123,7 @@ public async Task ParseBasicDocumentWithMultipleServersShouldSucceed() Url = new Uri("https://www.example.org/api").ToString(), Description = "The https endpoint" } - }, + ], Paths = new OpenApiPaths() }, options => options.Excluding(x => x.Workspace).Excluding(y => y.BaseUri)); } @@ -190,7 +190,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() var components = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["pet1"] = new OpenApiSchema() { @@ -200,7 +200,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() "id", "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -224,7 +224,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() { "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -249,7 +249,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() "code", "message" }, - Properties = new Dictionary + Properties = new() { ["code"] = new OpenApiSchema() { @@ -291,18 +291,18 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() Url = new Uri("http://opensource.org/licenses/MIT") } }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -343,7 +343,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -366,7 +366,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -377,7 +377,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -395,7 +395,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() { Description = "Pet to add to the store", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -408,7 +408,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -419,7 +419,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -430,7 +430,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -444,7 +444,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -471,7 +471,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -486,7 +486,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -497,7 +497,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -535,7 +535,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -546,7 +546,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -576,7 +576,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() var components = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["pet1"] = new OpenApiSchema() { @@ -586,7 +586,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() "id", "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -610,7 +610,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() { "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -635,7 +635,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() "code", "message" }, - Properties = new Dictionary + Properties = new() { ["code"] = new OpenApiSchema() { @@ -710,18 +710,18 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() Url = new Uri("http://opensource.org/licenses/MIT") } }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -767,7 +767,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -790,7 +790,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -801,7 +801,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -824,7 +824,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() { Description = "Pet to add to the store", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -837,7 +837,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -848,7 +848,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -859,7 +859,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -868,24 +868,24 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - Security = new List - { + Security = + [ new OpenApiSecurityRequirement { - [new OpenApiSecuritySchemeReference("securitySchemeName1")] = new List(), - [new OpenApiSecuritySchemeReference("securitySchemeName2")] = new List - { + [new OpenApiSecuritySchemeReference("securitySchemeName1")] = [], + [new OpenApiSecuritySchemeReference("securitySchemeName2")] = + [ "scope1", "scope2" - } + ] } - } + ] } } }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -912,7 +912,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -927,7 +927,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -938,7 +938,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -976,7 +976,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -987,7 +987,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -1014,19 +1014,19 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() Description = "tagDescription2" } }, - Security = new List - { + Security = + [ new OpenApiSecurityRequirement { - [new OpenApiSecuritySchemeReference("securitySchemeName1")] = new List(), - [new OpenApiSecuritySchemeReference("securitySchemeName2")] = new List - { + [new OpenApiSecuritySchemeReference("securitySchemeName1")] = [], + [new OpenApiSecuritySchemeReference("securitySchemeName2")] = + [ "scope1", "scope2", "scope3" - } + ] } - } + ] }; expected.RegisterComponents(); expected.SetReferenceHostDocument(); @@ -1101,7 +1101,7 @@ public async Task HeaderParameterShouldAllowExample() AllowReserved = true, Style = ParameterStyle.Simple, Explode = true, - Examples = + Examples = new Dictionary { { "uuid1", new OpenApiExample() { @@ -1247,7 +1247,7 @@ public async Task SerializesDoubleHopeReferences() { Type = JsonSchemaType.Object, Description = "A pet", - Properties = + Properties = new() { ["id"] = new OpenApiSchema { @@ -1272,7 +1272,7 @@ public async Task SerializesDoubleHopeReferences() document.AddComponent("PetReference", petSchemaReference); document.Paths.Add("/pets", new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -1282,7 +1282,7 @@ public async Task SerializesDoubleHopeReferences() ["200"] = new OpenApiResponse { Description = "A list of pets", - Content = + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -1338,7 +1338,7 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds() { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -1436,17 +1436,17 @@ public void ParseBasicDocumentWithServerVariableShouldSucceed() Version = "0.9.1", }, Servers = + [ + new OpenApiServer { - new OpenApiServer + Url = "http://www.example.org/api/{version}", + Description = "The http endpoint", + Variables = new Dictionary { - Url = "http://www.example.org/api/{version}", - Description = "The http endpoint", - Variables = new Dictionary - { - {"version", new OpenApiServerVariable {Default = "v2", Enum = ["v1", "v2"]}} - } + {"version", new OpenApiServerVariable {Default = "v2", Enum = ["v1", "v2"]}} } - }, + } + ], Paths = new() }; diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs index 91d2a6059..dee46bc98 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiEncodingTests.cs @@ -1,9 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Reader; using Xunit; @@ -41,7 +43,7 @@ public async Task ParseAdvancedEncodingShouldSucceed() new OpenApiEncoding { ContentType = "image/png, image/jpeg", - Headers = + Headers = new Dictionary { ["X-Rate-Limit-Limit"] = new OpenApiHeader() diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs index 8e5cb6389..fd7c5e478 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs @@ -2,11 +2,13 @@ // Licensed under the MIT license. using System; +using System.Collections.Generic; using System.IO; using System.Text.Json.Nodes; using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader; using Xunit; @@ -35,7 +37,7 @@ public async Task ParseAdvancedInfoShouldSucceed() Contact = new OpenApiContact { Email = "example@example.com", - Extensions = + Extensions = new Dictionary { ["x-twitter"] = new OpenApiAny("@exampleTwitterHandler") }, @@ -44,11 +46,14 @@ public async Task ParseAdvancedInfoShouldSucceed() }, License = new OpenApiLicense { - Extensions = { ["x-disclaimer"] = new OpenApiAny("Sample Extension String Disclaimer") }, + Extensions = new Dictionary + { + ["x-disclaimer"] = new OpenApiAny("Sample Extension String Disclaimer") + }, Name = "licenseName", Url = new Uri("http://www.example.com/url2") }, - Extensions = + Extensions = new Dictionary { ["x-something"] = new OpenApiAny("Sample Extension String Something"), ["x-contact"] = new OpenApiAny(new JsonObject() diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs index f60ec2820..7bdcf6047 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs @@ -1,11 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using FluentAssertions; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Reader; using Microsoft.OpenApi.Reader.ParseNodes; using Microsoft.OpenApi.Reader.V3; @@ -50,7 +52,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed() mediaType.Should().BeEquivalentTo( new OpenApiMediaType { - Examples = + Examples = new Dictionary { ["example1"] = new OpenApiExample() { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs index 1dd9ecce3..e22f02029 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs @@ -48,7 +48,7 @@ public async Task ParseOperationWithParameterWithNoLocationShouldSucceed() Description = "", OperationId = "loginUser", Parameters = - { + [ new OpenApiParameter { Name = "username", @@ -70,7 +70,7 @@ public async Task ParseOperationWithParameterWithNoLocationShouldSucceed() Type = JsonSchemaType.String } } - } + ] }; // Assert @@ -98,7 +98,7 @@ public void DeduplicatesTagReferences() Description = "", OperationId = "loginUser", Parameters = - { + [ new OpenApiParameter { Name = "password", @@ -110,7 +110,7 @@ public void DeduplicatesTagReferences() Type = JsonSchemaType.String } } - } + ] }; using var textWriter = new StringWriter(); var writer = new OpenApiJsonWriter(textWriter); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs index fd27c9416..7765545aa 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs @@ -110,19 +110,19 @@ public async Task ParseQueryParameterWithObjectTypeAndContentShouldSucceed() { In = ParameterLocation.Query, Name = "coordinates", - Content = + Content = new() { ["application/json"] = new() { Schema = new OpenApiSchema() { Type = JsonSchemaType.Object, - Required = + Required = new HashSet { "lat", "long" }, - Properties = + Properties = new() { ["lat"] = new OpenApiSchema() { @@ -273,7 +273,7 @@ public async Task ParseParameterWithExamplesShouldSucceed() Name = "username", Description = "username to fetch", Required = true, - Examples = + Examples = new Dictionary { ["example1"] = new OpenApiExample() { @@ -320,18 +320,18 @@ public void ParseParameterWithReferenceWorks() Version = "1.0.0", Title = "Swagger Petstore (Simple)" }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 0ea179f56..d9b4b1901 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -18,6 +18,7 @@ using System.Threading.Tasks; using System.Net.Http; using Microsoft.OpenApi.YamlReader; +using Microsoft.OpenApi.Models.Interfaces; namespace Microsoft.OpenApi.Readers.Tests.V3Tests { @@ -121,7 +122,7 @@ public void ParsePathFragmentShouldSucceed() new OpenApiPathItem { Summary = "externally referenced path item", - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation() { @@ -194,7 +195,7 @@ public void ParseBasicSchemaWithExampleShouldSucceed() new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["id"] = new OpenApiSchema() { @@ -206,7 +207,7 @@ public void ParseBasicSchemaWithExampleShouldSucceed() Type = JsonSchemaType.String } }, - Required = + Required = new HashSet { "name" }, @@ -240,12 +241,12 @@ public async Task ParseBasicSchemaWithReferenceShouldSucceed() var expectedComponents = new OpenApiComponents { - Schemas = + Schemas = new() { ["ErrorModel"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["code"] = new OpenApiSchema() { @@ -258,7 +259,7 @@ public async Task ParseBasicSchemaWithReferenceShouldSucceed() Type = JsonSchemaType.String } }, - Required = + Required = new HashSet { "message", "code" @@ -267,13 +268,13 @@ public async Task ParseBasicSchemaWithReferenceShouldSucceed() ["ExtendedErrorModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ErrorModel", result.Document), new OpenApiSchema { Type = JsonSchemaType.Object, - Required = {"rootCause"}, - Properties = + Required = new HashSet {"rootCause"}, + Properties = new() { ["rootCause"] = new OpenApiSchema() { @@ -281,7 +282,7 @@ public async Task ParseBasicSchemaWithReferenceShouldSucceed() } } } - } + ] } } }; @@ -297,7 +298,7 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() var expectedComponents = new OpenApiComponents { - Schemas = + Schemas = new() { ["Pet"] = new OpenApiSchema() { @@ -306,7 +307,7 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() { PropertyName = "petType" }, - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -317,7 +318,7 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() Type = JsonSchemaType.String } }, - Required = + Required = new HashSet { "name", "petType" @@ -327,41 +328,41 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() { Description = "A representation of a cat", AllOf = - { + [ new OpenApiSchemaReference("Pet", result.Document), new OpenApiSchema { Type = JsonSchemaType.Object, - Required = {"huntingSkill"}, - Properties = + Required = new HashSet{"huntingSkill"}, + Properties = new() { ["huntingSkill"] = new OpenApiSchema() { Type = JsonSchemaType.String, Description = "The measured skill for hunting", Enum = - { + [ "clueless", "lazy", "adventurous", "aggressive" - } + ] } } } - } + ] }, ["Dog"] = new OpenApiSchema() { Description = "A representation of a dog", AllOf = - { + [ new OpenApiSchemaReference("Pet", result.Document), new OpenApiSchema { Type = JsonSchemaType.Object, - Required = {"packSize"}, - Properties = + Required = new HashSet{"packSize"}, + Properties = new() { ["packSize"] = new OpenApiSchema() { @@ -373,7 +374,7 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() } } } - } + ] } } }; @@ -403,42 +404,42 @@ public async Task ParseExternalReferenceSchemaShouldSucceed() var expectedComponents = new OpenApiComponents { - Schemas = + Schemas = new() { ["RelativePathModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ExternalRelativePathModel", result.Document, "./FirstLevel/SecondLevel/ThridLevel/File.json") - } + ] }, ["SimpleRelativePathModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ExternalSimpleRelativePathModel", result.Document, "File.json") - } + ] }, ["AbsoluteWindowsPathModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ExternalAbsWindowsPathModel", result.Document, @"A:\Dir\File.json") - } + ] }, ["AbsoluteUnixPathModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ExternalAbsUnixPathModel", result.Document, "/Dir/File.json") - } + ] }, ["HttpsUrlModel"] = new OpenApiSchema() { AllOf = - { + [ new OpenApiSchemaReference("ExternalHttpsModel", result.Document, "https://host.lan:1234/path/to/file/resource.json") - } + ] } } }; diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs index ed864d240..cdab5c3ef 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSecuritySchemeTests.cs @@ -77,7 +77,7 @@ public async Task ParseOAuth2SecuritySchemeShouldSucceed() Implicit = new OpenApiOAuthFlow { AuthorizationUrl = new Uri("https://example.com/api/oauth/dialog"), - Scopes = + Scopes = new System.Collections.Generic.Dictionary { ["write:pets"] = "modify pets in your account", ["read:pets"] = "read your pets" diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs index 2bc407557..a6f724c66 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Writers; using VerifyXunit; @@ -19,19 +21,19 @@ public class OpenApiCallbackTests { private static OpenApiCallback AdvancedCallback => new() { - PathItems = + PathItems = new Dictionary { [RuntimeExpression.Build("$request.body#/url")] = new OpenApiPathItem() { - Operations = + Operations = new() { [HttpMethod.Post] = new() { RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/json"] = new() { @@ -59,19 +61,19 @@ public class OpenApiCallbackTests private static OpenApiCallback ReferencedCallback => new() { - PathItems = + PathItems = new Dictionary { [RuntimeExpression.Build("$request.body#/url")] = new OpenApiPathItem() { - Operations = + Operations = new() { [HttpMethod.Post] = new() { RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/json"] = new() { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs index b0607f57e..65c53b322 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs @@ -17,11 +17,11 @@ public class OpenApiComponentsTests { public static OpenApiComponents AdvancedComponents = new() { - Schemas = new Dictionary + Schemas = new() { ["schema1"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -66,11 +66,11 @@ public class OpenApiComponentsTests public static OpenApiComponents AdvancedComponentsWithReference = new() { - Schemas = new Dictionary + Schemas = new() { ["schema1"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -81,7 +81,7 @@ public class OpenApiComponentsTests }, ["schema2"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -123,7 +123,7 @@ public class OpenApiComponentsTests public static OpenApiComponents BrokenComponents = new() { - Schemas = new Dictionary + Schemas = new() { ["schema1"] = new OpenApiSchema() { @@ -134,8 +134,8 @@ public class OpenApiComponentsTests ["schema4"] = new OpenApiSchema() { Type = JsonSchemaType.String, - AllOf = new List - { + AllOf = + [ null, null, new OpenApiSchema() @@ -144,20 +144,20 @@ public class OpenApiComponentsTests }, null, null - } + ] } } }; public static OpenApiComponents TopLevelReferencingComponents = new() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchemaReference("schema2", null), ["schema2"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -170,12 +170,12 @@ public class OpenApiComponentsTests public static OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -186,7 +186,7 @@ public class OpenApiComponentsTests ["schema2"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -199,7 +199,7 @@ public class OpenApiComponentsTests public static OpenApiComponents TopLevelSelfReferencingComponents = new() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchemaReference("schema1", null) } @@ -207,11 +207,11 @@ public class OpenApiComponentsTests public static OpenApiComponents ComponentsWithPathItem = new OpenApiComponents { - Schemas = new Dictionary() + Schemas = new() { ["schema1"] = new OpenApiSchema() { - Properties = new Dictionary() + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -223,7 +223,7 @@ public class OpenApiComponentsTests ["schema2"] = new OpenApiSchema() { - Properties = new Dictionary() + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -236,14 +236,14 @@ public class OpenApiComponentsTests { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { Description = "Information about a new pet in the system", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs index aec4815e0..65f34c65b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs @@ -21,7 +21,7 @@ public class OpenApiContactTests Name = "API Support", Url = new("http://www.example.com/support"), Email = "support@example.com", - Extensions = new Dictionary + Extensions = new() { {"x-internal-id", new OpenApiAny(42)} } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 6c3498007..7b391c401 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -13,9 +13,7 @@ using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; -using Microsoft.OpenApi.Reader; using Microsoft.OpenApi.Writers; -using Microsoft.OpenApi.YamlReader; using Microsoft.VisualBasic; using VerifyXunit; using Xunit; @@ -27,13 +25,13 @@ public class OpenApiDocumentTests { public static readonly OpenApiComponents TopLevelReferencingComponents = new OpenApiComponents() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchemaReference("schema2", null), ["schema2"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -47,12 +45,12 @@ public class OpenApiDocumentTests public static readonly OpenApiComponents TopLevelSelfReferencingComponentsWithOtherProperties = new OpenApiComponents() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -65,7 +63,7 @@ public class OpenApiDocumentTests ["schema2"] = new OpenApiSchema() { Type = JsonSchemaType.Object, - Properties = + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -79,7 +77,7 @@ public class OpenApiDocumentTests public static readonly OpenApiComponents TopLevelSelfReferencingComponents = new OpenApiComponents() { - Schemas = + Schemas = new() { ["schema1"] = new OpenApiSchema() { @@ -119,7 +117,7 @@ public class OpenApiDocumentTests public static readonly OpenApiComponents AdvancedComponentsWithReference = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["pet"] = new OpenApiSchema() { @@ -129,7 +127,7 @@ public class OpenApiDocumentTests "id", "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -153,7 +151,7 @@ public class OpenApiDocumentTests { "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -178,7 +176,7 @@ public class OpenApiDocumentTests "code", "message" }, - Properties = new Dictionary + Properties = new() { ["code"] = new OpenApiSchema() { @@ -222,18 +220,18 @@ public class OpenApiDocumentTests Url = new Uri("http://opensource.org/licenses/MIT") } }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -274,7 +272,7 @@ public class OpenApiDocumentTests ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -297,7 +295,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -308,7 +306,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -326,7 +324,7 @@ public class OpenApiDocumentTests { Description = "Pet to add to the store", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -339,7 +337,7 @@ public class OpenApiDocumentTests ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -350,7 +348,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -361,7 +359,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -375,7 +373,7 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -402,7 +400,7 @@ public class OpenApiDocumentTests ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -417,7 +415,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -428,7 +426,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -466,7 +464,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -477,7 +475,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -496,7 +494,7 @@ public class OpenApiDocumentTests public static readonly OpenApiComponents AdvancedComponents = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["pet"] = new OpenApiSchema() { @@ -506,7 +504,7 @@ public class OpenApiDocumentTests "id", "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -530,7 +528,7 @@ public class OpenApiDocumentTests { "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -555,7 +553,7 @@ public class OpenApiDocumentTests "code", "message" }, - Properties = new Dictionary + Properties = new() { ["code"] = new OpenApiSchema() { @@ -598,25 +596,25 @@ public class OpenApiDocumentTests Url = new Uri("http://opensource.org/licenses/MIT") } }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", - Parameters = new List - { + Parameters = + [ new OpenApiParameter { Name = "tags", @@ -644,13 +642,13 @@ public class OpenApiDocumentTests Format = "int32" } } - }, + ], Responses = new OpenApiResponses { ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -673,7 +671,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -684,7 +682,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -702,7 +700,7 @@ public class OpenApiDocumentTests { Description = "Pet to add to the store", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -715,7 +713,7 @@ public class OpenApiDocumentTests ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -726,7 +724,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -737,7 +735,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -751,15 +749,15 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", - Parameters = new List - { + Parameters = + [ new OpenApiParameter { Name = "id", @@ -772,13 +770,13 @@ public class OpenApiDocumentTests Format = "int64" } } - }, + ], Responses = new OpenApiResponses { ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -793,7 +791,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -804,7 +802,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -818,8 +816,8 @@ public class OpenApiDocumentTests { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", - Parameters = new List - { + Parameters = + [ new OpenApiParameter { Name = "id", @@ -832,7 +830,7 @@ public class OpenApiDocumentTests Format = "int64" } } - }, + ], Responses = new OpenApiResponses { ["204"] = new OpenApiResponse @@ -842,7 +840,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -853,7 +851,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new OpenApiMediaType { @@ -881,14 +879,14 @@ public class OpenApiDocumentTests { ["newPet"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { Description = "Information about a new pet in the system", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -909,7 +907,7 @@ public class OpenApiDocumentTests }, Components = new OpenApiComponents { - Schemas = new Dictionary + Schemas = new() { ["Pet"] = new OpenApiSchema() { @@ -917,7 +915,7 @@ public class OpenApiDocumentTests { "id", "name" }, - Properties = new Dictionary + Properties = new() { ["id"] = new OpenApiSchema() { @@ -946,24 +944,24 @@ public class OpenApiDocumentTests Title = "Swagger Petstore (Simple)", Description = "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", }, - Servers = new List - { + Servers = + [ new OpenApiServer { Url = "http://petstore.swagger.io/api" } - }, + ], Paths = new OpenApiPaths { ["/add/{operand1}/{operand2}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { OperationId = "addByOperand1AndByOperand2", - Parameters = new List - { + Parameters = + [ new OpenApiParameter { Name = "operand1", @@ -973,12 +971,12 @@ public class OpenApiDocumentTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Integer, - Extensions = new Dictionary + Extensions = new() { ["my-extension"] = new OpenApiAny(4) } }, - Extensions = new Dictionary + Extensions = new() { ["my-extension"] = new OpenApiAny(4), } @@ -992,23 +990,23 @@ public class OpenApiDocumentTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Integer, - Extensions = new Dictionary + Extensions = new() { ["my-extension"] = new OpenApiAny(4) } }, - Extensions = new Dictionary + Extensions = new() { ["my-extension"] = new OpenApiAny(4), } }, - }, + ], Responses = new OpenApiResponses { ["200"] = new OpenApiResponse { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -1050,8 +1048,8 @@ public class OpenApiDocumentTests Url = new("http://opensource.org/licenses/MIT") } }, - Servers = new List - { + Servers = + [ new() { Url = "https://{endpoint}/openai", @@ -1063,19 +1061,19 @@ public class OpenApiDocumentTests } } } - }, + ], Paths = new() { ["/pets"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "tags", @@ -1103,13 +1101,13 @@ public class OpenApiDocumentTests Format = "int32" } } - }, + ], Responses = new() { ["200"] = new OpenApiResponse() { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -1132,7 +1130,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse() { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1143,7 +1141,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse() { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1161,7 +1159,7 @@ public class OpenApiDocumentTests { Description = "Pet to add to the store", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -1174,7 +1172,7 @@ public class OpenApiDocumentTests ["200"] = new OpenApiResponse() { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -1185,7 +1183,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse() { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1196,7 +1194,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse() { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1210,15 +1208,15 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", OperationId = "findPetById", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "id", @@ -1231,13 +1229,13 @@ public class OpenApiDocumentTests Format = "int64" } } - }, + ], Responses = new() { ["200"] = new OpenApiResponse() { Description = "pet response", - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -1252,7 +1250,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse() { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1263,7 +1261,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse() { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1277,8 +1275,8 @@ public class OpenApiDocumentTests { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", - Parameters = new List - { + Parameters = + [ new OpenApiParameter() { Name = "id", @@ -1291,7 +1289,7 @@ public class OpenApiDocumentTests Format = "int64" } } - }, + ], Responses = new() { ["204"] = new OpenApiResponse() @@ -1301,7 +1299,7 @@ public class OpenApiDocumentTests ["4XX"] = new OpenApiResponse() { Description = "unexpected client error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1312,7 +1310,7 @@ public class OpenApiDocumentTests ["5XX"] = new OpenApiResponse() { Description = "unexpected server error", - Content = new Dictionary + Content = new() { ["text/html"] = new() { @@ -1535,7 +1533,7 @@ public async Task SerializeDocumentWithReferenceButNoComponents() { ["/"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -1543,7 +1541,7 @@ public async Task SerializeDocumentWithReferenceButNoComponents() { ["200"] = new OpenApiResponse { - Content = new Dictionary() + Content = new() { ["application/json"] = new OpenApiMediaType { @@ -1578,12 +1576,12 @@ public async Task SerializeRelativePathAsV2JsonWorks() var doc = new OpenApiDocument() { Info = new OpenApiInfo() { Version = "1.0.0" }, - Servers = new List() { + Servers = [ new OpenApiServer() { Url = "/server1" } - } + ] }; // Act @@ -1608,12 +1606,12 @@ public async Task SerializeRelativePathWithHostAsV2JsonWorks() var doc = new OpenApiDocument() { Info = new OpenApiInfo() { Version = "1.0.0" }, - Servers = new List() { + Servers = [ new OpenApiServer() { Url = "//example.org/server1" } - } + ] }; // Act @@ -1637,12 +1635,12 @@ public async Task SerializeRelativeRootPathWithHostAsV2JsonWorks() var doc = new OpenApiDocument() { Info = new OpenApiInfo() { Version = "1.0.0" }, - Servers = new List() { + Servers = [ new OpenApiServer() { Url = "//example.org/" } - } + ] }; // Act @@ -1708,7 +1706,7 @@ public async Task SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollec { ["/foo"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -1775,7 +1773,7 @@ public async Task SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() { ["/foo"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new OpenApiOperation { @@ -1800,7 +1798,7 @@ public async Task SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() ["200"] = new OpenApiResponse { Description = "foo", - Content = new Dictionary + Content = new() { ["text/plain"] = new OpenApiMediaType { @@ -1831,7 +1829,7 @@ public void OpenApiDocumentCopyConstructorWithAnnotationsSucceeds() { var baseDocument = new OpenApiDocument { - Metadata = new Dictionary + Metadata = new() { ["key1"] = "value1", ["key2"] = 2 @@ -1856,13 +1854,13 @@ public void SerializeExamplesDoesNotThrowNullReferenceException() { ["test"] = new OpenApiPathItem() { - Operations = new Dictionary() + Operations = new() { [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/json"] = new OpenApiMediaType() { @@ -2079,7 +2077,7 @@ public async Task SerializeDocumentTagsWithMultipleExtensionsWorks() new OpenApiTag { Name = "tag1", - Extensions = new Dictionary + Extensions = new() { ["x-tag1"] = new OpenApiAny("tag1") } @@ -2087,7 +2085,7 @@ public async Task SerializeDocumentTagsWithMultipleExtensionsWorks() new OpenApiTag { Name = "tag2", - Extensions = new Dictionary + Extensions = new() { ["x-tag2"] = new OpenApiAny("tag2") } @@ -2108,7 +2106,7 @@ public void DeduplicatesTags() new OpenApiTag { Name = "tag1", - Extensions = new Dictionary + Extensions = new() { ["x-tag1"] = new OpenApiAny("tag1") } @@ -2116,7 +2114,7 @@ public void DeduplicatesTags() new OpenApiTag { Name = "tag2", - Extensions = new Dictionary + Extensions = new() { ["x-tag2"] = new OpenApiAny("tag2") } @@ -2124,7 +2122,7 @@ public void DeduplicatesTags() new OpenApiTag { Name = "tag1", - Extensions = new Dictionary + Extensions = new() { ["x-tag1"] = new OpenApiAny("tag1") } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs index 65ded8841..08300a4ff 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System.Collections.Generic; @@ -22,7 +22,7 @@ public class OpenApiInfoTests Contact = OpenApiContactTests.AdvanceContact, License = OpenApiLicenseTests.AdvanceLicense, Version = "1.1.1", - Extensions = new Dictionary + Extensions = new() { {"x-updated", new OpenApiAny("metadata")} } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs index 7daa55e29..acad2216a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLicenseTests.cs @@ -23,7 +23,7 @@ public class OpenApiLicenseTests { Name = "Apache 2.0", Url = new("http://www.apache.org/licenses/LICENSE-2.0.html"), - Extensions = new Dictionary + Extensions = new() { {"x-copyright", new OpenApiAny("Abc")} } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs index a6b4bc500..03b406adf 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiLinkTests.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Expressions; +using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Writers; @@ -21,7 +23,7 @@ public class OpenApiLinkTests private static OpenApiLink AdvancedLink => new() { OperationId = "operationId1", - Parameters = + Parameters = new Dictionary { ["parameter1"] = new() { @@ -46,7 +48,7 @@ public class OpenApiLinkTests private static OpenApiLink ReferencedLink => new() { OperationId = "operationId1", - Parameters = + Parameters = new Dictionary { ["parameter1"] = new() { @@ -124,8 +126,10 @@ public void LinkExtensionsSerializationWorks() // Arrange var link = new OpenApiLink() { - Extensions = { - { "x-display", new OpenApiAny("Abc") } + Extensions = new() + { + { "x-display", new OpenApiAny("Abc") + } } }; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs index ef1ebb420..3f3c93889 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs @@ -79,7 +79,8 @@ public class OpenApiMediaTypeTests public static OpenApiMediaType MediaTypeWithObjectExamples = new() { - Examples = { + Examples = new Dictionary + { ["object1"] = new OpenApiExample() { Value = new JsonObject @@ -436,7 +437,7 @@ public void MediaTypeCopyConstructorWorks() Example = 42, Examples = new Dictionary(), Encoding = new Dictionary(), - Extensions = new Dictionary() + Extensions = new() }; // Assert diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs index d7315d5ab..a862abdd6 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs @@ -44,7 +44,7 @@ public class OpenApiOperationTests { Description = "description2", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -62,7 +62,7 @@ public class OpenApiOperationTests ["200"] = new OpenApiResponseReference("response1"), ["400"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -76,14 +76,14 @@ public class OpenApiOperationTests } } }, - Servers = new List - { + Servers = + [ new() { Url = "http://server.com", Description = "serverDescription" } - }, + ], Metadata = new Dictionary { { "key1", "value1" }, { "key2", 2 } }, }; @@ -118,7 +118,7 @@ public class OpenApiOperationTests { Description = "description2", Required = true, - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -136,7 +136,7 @@ public class OpenApiOperationTests ["200"] = new OpenApiResponseReference("response1"), ["400"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -150,26 +150,26 @@ public class OpenApiOperationTests } } }, - Security = new List - { + Security = + [ new() { - [new OpenApiSecuritySchemeReference("securitySchemeId1", __advancedOperationWithTagsAndSecurity_supportingDocument)] = new List(), - [new OpenApiSecuritySchemeReference("securitySchemeId2", __advancedOperationWithTagsAndSecurity_supportingDocument)] = new List - { + [new OpenApiSecuritySchemeReference("securitySchemeId1", __advancedOperationWithTagsAndSecurity_supportingDocument)] = [], + [new OpenApiSecuritySchemeReference("securitySchemeId2", __advancedOperationWithTagsAndSecurity_supportingDocument)] = + [ "scopeName1", "scopeName2" - } + ] } - }, - Servers = new List - { + ], + Servers = + [ new() { Url = "http://server.com", Description = "serverDescription" } - } + ] }; private static OpenApiDocument __advancedOperationWithTagsAndSecurity_supportingDocument { @@ -222,13 +222,13 @@ private static OpenApiDocument __advancedOperationWithTagsAndSecurity_supporting ], RequestBody = new OpenApiRequestBody() { - Content = + Content = new() { ["application/x-www-form-urlencoded"] = new() { Schema = new OpenApiSchema() { - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { @@ -251,7 +251,7 @@ private static OpenApiDocument __advancedOperationWithTagsAndSecurity_supporting { Schema = new OpenApiSchema() { - Properties = + Properties = new() { ["name"] = new OpenApiSchema() { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs index da0c00d44..a9bb4ba78 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -45,13 +46,13 @@ public class OpenApiParameterTests { Title = "title2", Description = "description2", - OneOf = new List - { + OneOf = + [ new OpenApiSchema() { Type = JsonSchemaType.Number, Format = "double" }, new OpenApiSchema() { Type = JsonSchemaType.String } - } + ] }, - Examples = + Examples = new Dictionary { ["test"] = new OpenApiExample() { @@ -74,10 +75,10 @@ public class OpenApiParameterTests Items = new OpenApiSchema() { Enum = - { + [ new OpenApiAny("value1").Node, new OpenApiAny("value2").Node - } + ] } } }; @@ -131,7 +132,7 @@ public class OpenApiParameterTests { Type = JsonSchemaType.Object }, - Examples = + Examples = new Dictionary { ["test"] = new OpenApiExample() { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs index 863ce5145..8d037629b 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiRequestBodyTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Threading.Tasks; @@ -19,7 +20,7 @@ public class OpenApiRequestBodyTests { Description = "description", Required = true, - Content = + Content = new() { ["application/json"] = new() { @@ -36,7 +37,7 @@ public class OpenApiRequestBodyTests { Description = "description", Required = true, - Content = + Content = new() { ["application/json"] = new() { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs index 7d077b540..51decab10 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs @@ -9,6 +9,7 @@ using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Writers; using VerifyXunit; @@ -25,7 +26,7 @@ public class OpenApiResponseTests private static OpenApiResponse AdvancedV2Response => new OpenApiResponse { Description = "A complex object array response", - Content = + Content = new Dictionary { ["text/plain"] = new OpenApiMediaType { @@ -35,13 +36,13 @@ public class OpenApiResponseTests Items = new OpenApiSchemaReference("customType", null) }, Example = "Blabla", - Extensions = new Dictionary + Extensions = new() { ["myextension"] = new OpenApiAny("myextensionvalue"), }, } }, - Headers = + Headers = new Dictionary { ["X-Rate-Limit-Limit"] = new OpenApiHeader { @@ -64,7 +65,7 @@ public class OpenApiResponseTests private static OpenApiResponse AdvancedV3Response => new OpenApiResponse { Description = "A complex object array response", - Content = + Content = new Dictionary { ["text/plain"] = new OpenApiMediaType { @@ -74,13 +75,13 @@ public class OpenApiResponseTests Items = new OpenApiSchemaReference("customType", null) }, Example = "Blabla", - Extensions = new Dictionary + Extensions = new() { ["myextension"] = new OpenApiAny("myextensionvalue"), }, } }, - Headers = + Headers = new Dictionary { ["X-Rate-Limit-Limit"] = new OpenApiHeader { @@ -105,7 +106,7 @@ public class OpenApiResponseTests private static OpenApiResponse ReferencedV2Response => new OpenApiResponse { Description = "A complex object array response", - Content = + Content = new Dictionary { ["text/plain"] = new OpenApiMediaType { @@ -116,7 +117,7 @@ public class OpenApiResponseTests } } }, - Headers = + Headers = new Dictionary { ["X-Rate-Limit-Limit"] = new OpenApiHeader { @@ -141,7 +142,7 @@ public class OpenApiResponseTests private static OpenApiResponse ReferencedV3Response => new OpenApiResponse { Description = "A complex object array response", - Content = + Content = new Dictionary { ["text/plain"] = new OpenApiMediaType { @@ -152,7 +153,7 @@ public class OpenApiResponseTests } } }, - Headers = + Headers = new Dictionary { ["X-Rate-Limit-Limit"] = new OpenApiHeader { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index bc0056c5a..6e2f00656 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -44,11 +44,11 @@ public class OpenApiSchemaTests public static readonly OpenApiSchema AdvancedSchemaObject = new() { Title = "title1", - Properties = new Dictionary + Properties = new() { ["property1"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -63,11 +63,11 @@ public class OpenApiSchemaTests }, ["property4"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property5"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property6"] = new OpenApiSchema() { @@ -93,12 +93,12 @@ public class OpenApiSchemaTests public static readonly OpenApiSchema AdvancedSchemaWithAllOf = new() { Title = "title1", - AllOf = new List - { + AllOf = + [ new OpenApiSchema() { Title = "title2", - Properties = new Dictionary + Properties = new() { ["property1"] = new OpenApiSchema() { @@ -114,11 +114,11 @@ public class OpenApiSchemaTests new OpenApiSchema() { Title = "title3", - Properties = new Dictionary + Properties = new() { ["property3"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property4"] = new OpenApiSchema() { @@ -134,7 +134,7 @@ public class OpenApiSchemaTests }, Type = JsonSchemaType.Object | JsonSchemaType.Null, }, - }, + ], Type = JsonSchemaType.Object | JsonSchemaType.Null, ExternalDocs = new() { @@ -161,12 +161,12 @@ public class OpenApiSchemaTests { Title = "title1", Required = new HashSet { "property1" }, - Properties = new Dictionary + Properties = new() { ["property1"] = new OpenApiSchema() { Required = new HashSet { "property3" }, - Properties = new Dictionary + Properties = new() { ["property2"] = new OpenApiSchema() { @@ -183,11 +183,11 @@ public class OpenApiSchemaTests }, ["property4"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property5"] = new OpenApiSchema() { - Properties = new Dictionary + Properties = new() { ["property6"] = new OpenApiSchema() { @@ -417,15 +417,15 @@ public async Task SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInC // Arrange var schema = new OpenApiSchema { - OneOf = new List - { + OneOf = + [ new OpenApiSchema() { Type = JsonSchemaType.Number, Format = "decimal" }, new OpenApiSchema() { Type = JsonSchemaType.String }, - } + ] }; var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); @@ -536,7 +536,7 @@ public void CloningSchemaExtensionsWorks() // Arrange var schema = new OpenApiSchema { - Extensions = + Extensions = new() { { "x-myextension", new OpenApiAny(42) } } @@ -547,7 +547,7 @@ public void CloningSchemaExtensionsWorks() Assert.Single(schemaCopy.Extensions); // Act && Assert - schemaCopy.Extensions = new Dictionary + schemaCopy.Extensions = new() { { "x-myextension" , new OpenApiAny(40) } }; @@ -573,15 +573,15 @@ public void OpenApiWalkerVisitsOpenApiSchemaNot() { ["/foo"] = new OpenApiPathItem() { - Parameters = new[] - { + Parameters = + [ new OpenApiParameter() { Name = "foo", In = ParameterLocation.Query, Schema = outerSchema, } - } + ] } } }; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs index 73ac0d0b7..2cb7f1da6 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiTagTests.cs @@ -25,7 +25,7 @@ public class OpenApiTagTests Name = "pet", Description = "Pets operations", ExternalDocs = OpenApiExternalDocsTests.AdvanceExDocs, - Extensions = new Dictionary + Extensions = new() { {"x-tag-extension", null} } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs index 9ff3569d4..98ec758c8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs @@ -21,7 +21,7 @@ public class OpenApiXmlTests Prefix = "sample", Wrapped = true, Attribute = true, - Extensions = new Dictionary + Extensions = new() { {"x-xml-extension", new OpenApiAny(7)} } diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs index 9da36b512..02a7308a3 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs @@ -12,6 +12,8 @@ using Microsoft.OpenApi.Writers; using VerifyXunit; using Xunit; +using System.Collections.Generic; +using Microsoft.OpenApi.Models.Interfaces; namespace Microsoft.OpenApi.Tests.Models.References { @@ -171,7 +173,7 @@ public void OpenApiHeaderTargetShouldResolveReference() { Components = new OpenApiComponents { - Headers = + Headers = new Dictionary { { "header1", new OpenApiHeader { diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 140cfd46c..bcec5fb01 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -183,7 +183,7 @@ namespace Microsoft.OpenApi.Extensions } public static class OpenApiServerExtensions { - public static string? ReplaceServerUrlVariables(this Microsoft.OpenApi.Models.OpenApiServer server, System.Collections.Generic.IDictionary? values = null) { } + public static string? ReplaceServerUrlVariables(this Microsoft.OpenApi.Models.OpenApiServer server, System.Collections.Generic.Dictionary? values = null) { } } public static class OpenApiTypeMapper { @@ -200,12 +200,12 @@ namespace Microsoft.OpenApi.Interfaces public interface IDiagnostic { } public interface IMetadataContainer { - System.Collections.Generic.IDictionary? Metadata { get; set; } + System.Collections.Generic.Dictionary? Metadata { get; set; } } public interface IOpenApiElement { } public interface IOpenApiExtensible : Microsoft.OpenApi.Interfaces.IOpenApiElement { - System.Collections.Generic.IDictionary? Extensions { get; set; } + System.Collections.Generic.Dictionary? Extensions { get; set; } } public interface IOpenApiExtension { @@ -213,7 +213,7 @@ namespace Microsoft.OpenApi.Interfaces } public interface IOpenApiReadOnlyExtensible { - System.Collections.Generic.IDictionary? Extensions { get; } + System.Collections.Generic.Dictionary? Extensions { get; } } public interface IOpenApiReader { @@ -355,10 +355,10 @@ namespace Microsoft.OpenApi.Models.Interfaces { bool AllowEmptyValue { get; } bool AllowReserved { get; } - System.Collections.Generic.IDictionary? Content { get; } + System.Collections.Generic.Dictionary? Content { get; } bool Deprecated { get; } System.Text.Json.Nodes.JsonNode? Example { get; } - System.Collections.Generic.IDictionary? Examples { get; } + System.Collections.Generic.Dictionary? Examples { get; } bool Explode { get; } bool Required { get; } Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } @@ -368,7 +368,7 @@ namespace Microsoft.OpenApi.Models.Interfaces { string? OperationId { get; } string? OperationRef { get; } - System.Collections.Generic.IDictionary? Parameters { get; } + System.Collections.Generic.Dictionary? Parameters { get; } Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; } Microsoft.OpenApi.Models.OpenApiServer? Server { get; } } @@ -376,10 +376,10 @@ namespace Microsoft.OpenApi.Models.Interfaces { bool AllowEmptyValue { get; } bool AllowReserved { get; } - System.Collections.Generic.IDictionary? Content { get; } + System.Collections.Generic.Dictionary? Content { get; } bool Deprecated { get; } System.Text.Json.Nodes.JsonNode? Example { get; } - System.Collections.Generic.IDictionary? Examples { get; } + System.Collections.Generic.Dictionary? Examples { get; } bool Explode { get; } Microsoft.OpenApi.Models.ParameterLocation? In { get; } string? Name { get; } @@ -389,9 +389,9 @@ namespace Microsoft.OpenApi.Models.Interfaces } public interface IOpenApiPathItem : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - System.Collections.Generic.IDictionary? Operations { get; } - System.Collections.Generic.IList? Parameters { get; } - System.Collections.Generic.IList? Servers { get; } + System.Collections.Generic.Dictionary? Operations { get; } + System.Collections.Generic.List? Parameters { get; } + System.Collections.Generic.List? Servers { get; } } public interface IOpenApiReadOnlyDescribedElement : Microsoft.OpenApi.Interfaces.IOpenApiElement { @@ -399,36 +399,36 @@ namespace Microsoft.OpenApi.Models.Interfaces } public interface IOpenApiRequestBody : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - System.Collections.Generic.IDictionary? Content { get; } + System.Collections.Generic.Dictionary? Content { get; } bool Required { get; } Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer); System.Collections.Generic.IEnumerable? ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer); } public interface IOpenApiResponse : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { - System.Collections.Generic.IDictionary? Content { get; } - System.Collections.Generic.IDictionary? Headers { get; } - System.Collections.Generic.IDictionary? Links { get; } + System.Collections.Generic.Dictionary? Content { get; } + System.Collections.Generic.Dictionary? Headers { get; } + System.Collections.Generic.Dictionary? Links { get; } } public interface IOpenApiSchema : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement { Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; } bool AdditionalPropertiesAllowed { get; } - System.Collections.Generic.IList? AllOf { get; } - System.Collections.Generic.IDictionary? Annotations { get; } - System.Collections.Generic.IList? AnyOf { get; } + System.Collections.Generic.List? AllOf { get; } + System.Collections.Generic.Dictionary? Annotations { get; } + System.Collections.Generic.List? AnyOf { get; } string? Comment { get; } string? Const { get; } System.Text.Json.Nodes.JsonNode? Default { get; } - System.Collections.Generic.IDictionary? Definitions { get; } - System.Collections.Generic.IDictionary>? DependentRequired { get; } + System.Collections.Generic.Dictionary? Definitions { get; } + System.Collections.Generic.Dictionary>? DependentRequired { get; } bool Deprecated { get; } Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; } string? DynamicAnchor { get; } string? DynamicRef { get; } - System.Collections.Generic.IList? Enum { get; } + System.Collections.Generic.List? Enum { get; } System.Text.Json.Nodes.JsonNode? Example { get; } - System.Collections.Generic.IList? Examples { get; } + System.Collections.Generic.List? Examples { get; } string? ExclusiveMaximum { get; } string? ExclusiveMinimum { get; } Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } @@ -445,19 +445,19 @@ namespace Microsoft.OpenApi.Models.Interfaces string? Minimum { get; } decimal? MultipleOf { get; } Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } - System.Collections.Generic.IList? OneOf { get; } + System.Collections.Generic.List? OneOf { get; } string? Pattern { get; } - System.Collections.Generic.IDictionary? PatternProperties { get; } - System.Collections.Generic.IDictionary? Properties { get; } + System.Collections.Generic.Dictionary? PatternProperties { get; } + System.Collections.Generic.Dictionary? Properties { get; } bool ReadOnly { get; } - System.Collections.Generic.ISet? Required { get; } + System.Collections.Generic.HashSet? Required { get; } System.Uri? Schema { get; } string? Title { get; } Microsoft.OpenApi.Models.JsonSchemaType? Type { get; } bool UnevaluatedProperties { get; } bool? UniqueItems { get; } - System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; } - System.Collections.Generic.IDictionary? Vocabulary { get; } + System.Collections.Generic.Dictionary? UnrecognizedKeywords { get; } + System.Collections.Generic.Dictionary? Vocabulary { get; } bool WriteOnly { get; } Microsoft.OpenApi.Models.OpenApiXml? Xml { get; } } @@ -497,7 +497,7 @@ namespace Microsoft.OpenApi.Models public class OpenApiCallback : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback { public OpenApiCallback() { } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public System.Collections.Generic.Dictionary? PathItems { get; set; } public void AddPathItem(Microsoft.OpenApi.Expressions.RuntimeExpression expression, Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem pathItem) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CreateShallowCopy() { } @@ -509,17 +509,17 @@ namespace Microsoft.OpenApi.Models { public OpenApiComponents() { } public OpenApiComponents(Microsoft.OpenApi.Models.OpenApiComponents? components) { } - public System.Collections.Generic.IDictionary? Callbacks { get; set; } - public System.Collections.Generic.IDictionary? Examples { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } - public System.Collections.Generic.IDictionary? Headers { get; set; } - public System.Collections.Generic.IDictionary? Links { get; set; } - public System.Collections.Generic.IDictionary? Parameters { get; set; } - public System.Collections.Generic.IDictionary? PathItems { get; set; } - public System.Collections.Generic.IDictionary? RequestBodies { get; set; } - public System.Collections.Generic.IDictionary? Responses { get; set; } - public System.Collections.Generic.IDictionary? Schemas { get; set; } - public System.Collections.Generic.IDictionary? SecuritySchemes { get; set; } + public System.Collections.Generic.Dictionary? Callbacks { get; set; } + public System.Collections.Generic.Dictionary? Examples { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Headers { get; set; } + public System.Collections.Generic.Dictionary? Links { get; set; } + public System.Collections.Generic.Dictionary? Parameters { get; set; } + public System.Collections.Generic.Dictionary? PathItems { get; set; } + public System.Collections.Generic.Dictionary? RequestBodies { get; set; } + public System.Collections.Generic.Dictionary? Responses { get; set; } + public System.Collections.Generic.Dictionary? Schemas { get; set; } + public System.Collections.Generic.Dictionary? SecuritySchemes { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -687,7 +687,7 @@ namespace Microsoft.OpenApi.Models public OpenApiContact() { } public OpenApiContact(Microsoft.OpenApi.Models.OpenApiContact contact) { } public string? Email { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? Name { get; set; } public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -698,8 +698,8 @@ namespace Microsoft.OpenApi.Models { public OpenApiDiscriminator() { } public OpenApiDiscriminator(Microsoft.OpenApi.Models.OpenApiDiscriminator discriminator) { } - public System.Collections.Generic.IDictionary? Extensions { get; set; } - public System.Collections.Generic.IDictionary? Mapping { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Mapping { get; set; } public string? PropertyName { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -711,16 +711,16 @@ namespace Microsoft.OpenApi.Models public OpenApiDocument(Microsoft.OpenApi.Models.OpenApiDocument? document) { } public System.Uri BaseUri { get; } public Microsoft.OpenApi.Models.OpenApiComponents? Components { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public Microsoft.OpenApi.Models.OpenApiInfo Info { get; set; } public System.Uri? JsonSchemaDialect { get; set; } - public System.Collections.Generic.IDictionary? Metadata { get; set; } + public System.Collections.Generic.Dictionary? Metadata { get; set; } public Microsoft.OpenApi.Models.OpenApiPaths Paths { get; set; } - public System.Collections.Generic.IList? Security { get; set; } - public System.Collections.Generic.IList? Servers { get; set; } - public System.Collections.Generic.ISet? Tags { get; set; } - public System.Collections.Generic.IDictionary? Webhooks { get; set; } + public System.Collections.Generic.List? Security { get; set; } + public System.Collections.Generic.List? Servers { get; set; } + public System.Collections.Generic.HashSet? Tags { get; set; } + public System.Collections.Generic.Dictionary? Webhooks { get; set; } public Microsoft.OpenApi.Services.OpenApiWorkspace? Workspace { get; set; } public bool AddComponent(string id, T componentToRegister) { } public System.Threading.Tasks.Task GetHashCodeAsync(System.Threading.CancellationToken cancellationToken = default) { } @@ -742,8 +742,8 @@ namespace Microsoft.OpenApi.Models public bool? AllowReserved { get; set; } public string? ContentType { get; set; } public bool? Explode { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } - public System.Collections.Generic.IDictionary? Headers { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Headers { get; set; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -762,7 +762,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiExample() { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? ExternalValue { get; set; } public string? Summary { get; set; } public System.Text.Json.Nodes.JsonNode? Value { get; set; } @@ -775,8 +775,8 @@ namespace Microsoft.OpenApi.Models where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { protected OpenApiExtensibleDictionary() { } - protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary, System.Collections.Generic.IDictionary? extensions = null) { } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary, System.Collections.Generic.Dictionary? extensions = null) { } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -786,7 +786,7 @@ namespace Microsoft.OpenApi.Models public OpenApiExternalDocs() { } public OpenApiExternalDocs(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -797,13 +797,13 @@ namespace Microsoft.OpenApi.Models public OpenApiHeader() { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } - public System.Collections.Generic.IDictionary? Content { get; set; } + public System.Collections.Generic.Dictionary? Content { get; set; } public bool Deprecated { get; set; } public string? Description { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } - public System.Collections.Generic.IDictionary? Examples { get; set; } + public System.Collections.Generic.Dictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public bool Required { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; set; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; set; } @@ -818,7 +818,7 @@ namespace Microsoft.OpenApi.Models public OpenApiInfo(Microsoft.OpenApi.Models.OpenApiInfo info) { } public Microsoft.OpenApi.Models.OpenApiContact? Contact { get; set; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiLicense? License { get; set; } public string? Summary { get; set; } public System.Uri? TermsOfService { get; set; } @@ -832,7 +832,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiLicense() { } public OpenApiLicense(Microsoft.OpenApi.Models.OpenApiLicense license) { } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? Identifier { get; set; } public string? Name { get; set; } public System.Uri? Url { get; set; } @@ -844,10 +844,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiLink() { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? OperationId { get; set; } public string? OperationRef { get; set; } - public System.Collections.Generic.IDictionary? Parameters { get; set; } + public System.Collections.Generic.Dictionary? Parameters { get; set; } public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; set; } public Microsoft.OpenApi.Models.OpenApiServer? Server { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CreateShallowCopy() { } @@ -859,10 +859,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiMediaType() { } public OpenApiMediaType(Microsoft.OpenApi.Models.OpenApiMediaType? mediaType) { } - public System.Collections.Generic.IDictionary? Encoding { get; set; } + public System.Collections.Generic.Dictionary? Encoding { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } - public System.Collections.Generic.IDictionary? Examples { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Examples { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -873,9 +873,9 @@ namespace Microsoft.OpenApi.Models public OpenApiOAuthFlow() { } public OpenApiOAuthFlow(Microsoft.OpenApi.Models.OpenApiOAuthFlow oAuthFlow) { } public System.Uri? AuthorizationUrl { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public System.Uri? RefreshUrl { get; set; } - public System.Collections.Generic.IDictionary? Scopes { get; set; } + public System.Collections.Generic.Dictionary? Scopes { get; set; } public System.Uri? TokenUrl { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -887,7 +887,7 @@ namespace Microsoft.OpenApi.Models public OpenApiOAuthFlows(Microsoft.OpenApi.Models.OpenApiOAuthFlows oAuthFlows) { } public Microsoft.OpenApi.Models.OpenApiOAuthFlow? AuthorizationCode { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlow? ClientCredentials { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlow? Implicit { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlow? Password { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -899,20 +899,20 @@ namespace Microsoft.OpenApi.Models public const bool DeprecatedDefault = false; public OpenApiOperation() { } public OpenApiOperation(Microsoft.OpenApi.Models.OpenApiOperation operation) { } - public System.Collections.Generic.IDictionary? Callbacks { get; set; } + public System.Collections.Generic.Dictionary? Callbacks { get; set; } public bool Deprecated { get; set; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } - public System.Collections.Generic.IDictionary? Metadata { get; set; } + public System.Collections.Generic.Dictionary? Metadata { get; set; } public string? OperationId { get; set; } - public System.Collections.Generic.IList? Parameters { get; set; } + public System.Collections.Generic.List? Parameters { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody? RequestBody { get; set; } public Microsoft.OpenApi.Models.OpenApiResponses? Responses { get; set; } - public System.Collections.Generic.IList? Security { get; set; } - public System.Collections.Generic.IList? Servers { get; set; } + public System.Collections.Generic.List? Security { get; set; } + public System.Collections.Generic.List? Servers { get; set; } public string? Summary { get; set; } - public System.Collections.Generic.ISet? Tags { get; set; } + public System.Collections.Generic.HashSet? Tags { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -922,13 +922,13 @@ namespace Microsoft.OpenApi.Models public OpenApiParameter() { } public bool AllowEmptyValue { get; set; } public bool AllowReserved { get; set; } - public System.Collections.Generic.IDictionary? Content { get; set; } + public System.Collections.Generic.Dictionary? Content { get; set; } public bool Deprecated { get; set; } public string? Description { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } - public System.Collections.Generic.IDictionary? Examples { get; set; } + public System.Collections.Generic.Dictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } public string? Name { get; set; } public bool Required { get; set; } @@ -943,10 +943,10 @@ namespace Microsoft.OpenApi.Models { public OpenApiPathItem() { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } - public System.Collections.Generic.IDictionary? Operations { get; set; } - public System.Collections.Generic.IList? Parameters { get; set; } - public System.Collections.Generic.IList? Servers { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Operations { get; set; } + public System.Collections.Generic.List? Parameters { get; set; } + public System.Collections.Generic.List? Servers { get; set; } public string? Summary { get; set; } public void AddOperation(System.Net.Http.HttpMethod operationType, Microsoft.OpenApi.Models.OpenApiOperation operation) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } @@ -981,9 +981,9 @@ namespace Microsoft.OpenApi.Models public class OpenApiRequestBody : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody { public OpenApiRequestBody() { } - public System.Collections.Generic.IDictionary? Content { get; set; } + public System.Collections.Generic.Dictionary? Content { get; set; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public bool Required { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public System.Collections.Generic.IEnumerable ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -995,11 +995,11 @@ namespace Microsoft.OpenApi.Models public class OpenApiResponse : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse { public OpenApiResponse() { } - public System.Collections.Generic.IDictionary? Content { get; set; } + public System.Collections.Generic.Dictionary? Content { get; set; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } - public System.Collections.Generic.IDictionary? Headers { get; set; } - public System.Collections.Generic.IDictionary? Links { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Headers { get; set; } + public System.Collections.Generic.Dictionary? Links { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1015,25 +1015,25 @@ namespace Microsoft.OpenApi.Models public OpenApiSchema() { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; set; } public bool AdditionalPropertiesAllowed { get; set; } - public System.Collections.Generic.IList? AllOf { get; set; } - public System.Collections.Generic.IDictionary? Annotations { get; set; } - public System.Collections.Generic.IList? AnyOf { get; set; } + public System.Collections.Generic.List? AllOf { get; set; } + public System.Collections.Generic.Dictionary? Annotations { get; set; } + public System.Collections.Generic.List? AnyOf { get; set; } public string? Comment { get; set; } public string? Const { get; set; } public System.Text.Json.Nodes.JsonNode? Default { get; set; } - public System.Collections.Generic.IDictionary? Definitions { get; set; } - public System.Collections.Generic.IDictionary>? DependentRequired { get; set; } + public System.Collections.Generic.Dictionary? Definitions { get; set; } + public System.Collections.Generic.Dictionary>? DependentRequired { get; set; } public bool Deprecated { get; set; } public string? Description { get; set; } public Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; set; } public string? DynamicAnchor { get; set; } public string? DynamicRef { get; set; } - public System.Collections.Generic.IList? Enum { get; set; } + public System.Collections.Generic.List? Enum { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } - public System.Collections.Generic.IList? Examples { get; set; } + public System.Collections.Generic.List? Examples { get; set; } public string? ExclusiveMaximum { get; set; } public string? ExclusiveMinimum { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public string? Format { get; set; } public string? Id { get; set; } @@ -1048,19 +1048,19 @@ namespace Microsoft.OpenApi.Models public string? Minimum { get; set; } public decimal? MultipleOf { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; set; } - public System.Collections.Generic.IList? OneOf { get; set; } + public System.Collections.Generic.List? OneOf { get; set; } public string? Pattern { get; set; } - public System.Collections.Generic.IDictionary? PatternProperties { get; set; } - public System.Collections.Generic.IDictionary? Properties { get; set; } + public System.Collections.Generic.Dictionary? PatternProperties { get; set; } + public System.Collections.Generic.Dictionary? Properties { get; set; } public bool ReadOnly { get; set; } - public System.Collections.Generic.ISet? Required { get; set; } + public System.Collections.Generic.HashSet? Required { get; set; } public System.Uri? Schema { get; set; } public string? Title { get; set; } public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; set; } public bool UnevaluatedProperties { get; set; } public bool? UniqueItems { get; set; } - public System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; set; } - public System.Collections.Generic.IDictionary? Vocabulary { get; set; } + public System.Collections.Generic.Dictionary? UnrecognizedKeywords { get; set; } + public System.Collections.Generic.Dictionary? Vocabulary { get; set; } public bool WriteOnly { get; set; } public Microsoft.OpenApi.Models.OpenApiXml? Xml { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CreateShallowCopy() { } @@ -1068,7 +1068,7 @@ namespace Microsoft.OpenApi.Models public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiSecurityRequirement : System.Collections.Generic.Dictionary>, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable + public class OpenApiSecurityRequirement : System.Collections.Generic.Dictionary>, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiSecurityRequirement() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1080,7 +1080,7 @@ namespace Microsoft.OpenApi.Models public OpenApiSecurityScheme() { } public string? BearerFormat { get; set; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } public string? Name { get; set; } @@ -1097,9 +1097,9 @@ namespace Microsoft.OpenApi.Models public OpenApiServer() { } public OpenApiServer(Microsoft.OpenApi.Models.OpenApiServer server) { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? Url { get; set; } - public System.Collections.Generic.IDictionary? Variables { get; set; } + public System.Collections.Generic.Dictionary? Variables { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1111,7 +1111,7 @@ namespace Microsoft.OpenApi.Models public string? Default { get; set; } public string? Description { get; set; } public System.Collections.Generic.List? Enum { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1120,7 +1120,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiTag() { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public string? Name { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CreateShallowCopy() { } @@ -1133,7 +1133,7 @@ namespace Microsoft.OpenApi.Models public OpenApiXml() { } public OpenApiXml(Microsoft.OpenApi.Models.OpenApiXml xml) { } public bool Attribute { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; set; } + public System.Collections.Generic.Dictionary? Extensions { get; set; } public string? Name { get; set; } public System.Uri? Namespace { get; set; } public string? Prefix { get; set; } @@ -1235,7 +1235,7 @@ namespace Microsoft.OpenApi.Models.References public class OpenApiCallbackReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback { public OpenApiCallbackReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public System.Collections.Generic.Dictionary? PathItems { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiCallback CreateShallowCopy() { } @@ -1245,7 +1245,7 @@ namespace Microsoft.OpenApi.Models.References { public OpenApiExampleReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public string? ExternalValue { get; } public string? Summary { get; set; } public System.Text.Json.Nodes.JsonNode? Value { get; } @@ -1258,13 +1258,13 @@ namespace Microsoft.OpenApi.Models.References public OpenApiHeaderReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public bool AllowEmptyValue { get; } public bool AllowReserved { get; } - public System.Collections.Generic.IDictionary? Content { get; } + public System.Collections.Generic.Dictionary? Content { get; } public bool Deprecated { get; } public string? Description { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; } - public System.Collections.Generic.IDictionary? Examples { get; } + public System.Collections.Generic.Dictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } @@ -1275,10 +1275,10 @@ namespace Microsoft.OpenApi.Models.References { public OpenApiLinkReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public string? OperationId { get; } public string? OperationRef { get; } - public System.Collections.Generic.IDictionary? Parameters { get; } + public System.Collections.Generic.Dictionary? Parameters { get; } public Microsoft.OpenApi.Models.RuntimeExpressionAnyWrapper? RequestBody { get; } public Microsoft.OpenApi.Models.OpenApiServer? Server { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiLink CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiLink source) { } @@ -1290,13 +1290,13 @@ namespace Microsoft.OpenApi.Models.References public OpenApiParameterReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public bool AllowEmptyValue { get; } public bool AllowReserved { get; } - public System.Collections.Generic.IDictionary? Content { get; } + public System.Collections.Generic.Dictionary? Content { get; } public bool Deprecated { get; } public string? Description { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; } - public System.Collections.Generic.IDictionary? Examples { get; } + public System.Collections.Generic.Dictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } public string? Name { get; } public bool Required { get; } @@ -1309,10 +1309,10 @@ namespace Microsoft.OpenApi.Models.References { public OpenApiPathItemReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } - public System.Collections.Generic.IDictionary? Operations { get; } - public System.Collections.Generic.IList? Parameters { get; } - public System.Collections.Generic.IList? Servers { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Operations { get; } + public System.Collections.Generic.List? Parameters { get; } + public System.Collections.Generic.List? Servers { get; } public string? Summary { get; set; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } @@ -1321,9 +1321,9 @@ namespace Microsoft.OpenApi.Models.References public class OpenApiRequestBodyReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiRequestBody { public OpenApiRequestBodyReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } - public System.Collections.Generic.IDictionary? Content { get; } + public System.Collections.Generic.Dictionary? Content { get; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiParameter? ConvertToBodyParameter(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public System.Collections.Generic.IEnumerable? ConvertToFormDataParameters(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1334,11 +1334,11 @@ namespace Microsoft.OpenApi.Models.References public class OpenApiResponseReference : Microsoft.OpenApi.Models.References.BaseOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse { public OpenApiResponseReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } - public System.Collections.Generic.IDictionary? Content { get; } + public System.Collections.Generic.Dictionary? Content { get; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } - public System.Collections.Generic.IDictionary? Headers { get; } - public System.Collections.Generic.IDictionary? Links { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Headers { get; } + public System.Collections.Generic.Dictionary? Links { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse source) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiResponse CreateShallowCopy() { } } @@ -1347,25 +1347,25 @@ namespace Microsoft.OpenApi.Models.References public OpenApiSchemaReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? AdditionalProperties { get; } public bool AdditionalPropertiesAllowed { get; } - public System.Collections.Generic.IList? AllOf { get; } - public System.Collections.Generic.IDictionary? Annotations { get; } - public System.Collections.Generic.IList? AnyOf { get; } + public System.Collections.Generic.List? AllOf { get; } + public System.Collections.Generic.Dictionary? Annotations { get; } + public System.Collections.Generic.List? AnyOf { get; } public string? Comment { get; } public string? Const { get; } public System.Text.Json.Nodes.JsonNode? Default { get; } - public System.Collections.Generic.IDictionary? Definitions { get; } - public System.Collections.Generic.IDictionary>? DependentRequired { get; } + public System.Collections.Generic.Dictionary? Definitions { get; } + public System.Collections.Generic.Dictionary>? DependentRequired { get; } public bool Deprecated { get; } public string? Description { get; set; } public Microsoft.OpenApi.Models.OpenApiDiscriminator? Discriminator { get; } public string? DynamicAnchor { get; } public string? DynamicRef { get; } - public System.Collections.Generic.IList? Enum { get; } + public System.Collections.Generic.List? Enum { get; } public System.Text.Json.Nodes.JsonNode? Example { get; } - public System.Collections.Generic.IList? Examples { get; } + public System.Collections.Generic.List? Examples { get; } public string? ExclusiveMaximum { get; } public string? ExclusiveMinimum { get; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Format { get; } public string? Id { get; } @@ -1380,19 +1380,19 @@ namespace Microsoft.OpenApi.Models.References public string? Minimum { get; } public decimal? MultipleOf { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } - public System.Collections.Generic.IList? OneOf { get; } + public System.Collections.Generic.List? OneOf { get; } public string? Pattern { get; } - public System.Collections.Generic.IDictionary? PatternProperties { get; } - public System.Collections.Generic.IDictionary? Properties { get; } + public System.Collections.Generic.Dictionary? PatternProperties { get; } + public System.Collections.Generic.Dictionary? Properties { get; } public bool ReadOnly { get; } - public System.Collections.Generic.ISet? Required { get; } + public System.Collections.Generic.HashSet? Required { get; } public System.Uri? Schema { get; } public string? Title { get; } public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; } public bool UnevaluatedProperties { get; } public bool? UniqueItems { get; } - public System.Collections.Generic.IDictionary? UnrecognizedKeywords { get; } - public System.Collections.Generic.IDictionary? Vocabulary { get; } + public System.Collections.Generic.Dictionary? UnrecognizedKeywords { get; } + public System.Collections.Generic.Dictionary? Vocabulary { get; } public bool WriteOnly { get; } public Microsoft.OpenApi.Models.OpenApiXml? Xml { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema source) { } @@ -1406,7 +1406,7 @@ namespace Microsoft.OpenApi.Models.References public OpenApiSecuritySchemeReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public string? BearerFormat { get; } public string? Description { get; set; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } public string? Name { get; } @@ -1420,7 +1420,7 @@ namespace Microsoft.OpenApi.Models.References { public OpenApiTagReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public string? Description { get; } - public System.Collections.Generic.IDictionary? Extensions { get; } + public System.Collections.Generic.Dictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Name { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? Target { get; } @@ -1433,9 +1433,9 @@ namespace Microsoft.OpenApi.Reader public class OpenApiDiagnostic : Microsoft.OpenApi.Interfaces.IDiagnostic { public OpenApiDiagnostic() { } - public System.Collections.Generic.IList Errors { get; set; } + public System.Collections.Generic.List Errors { get; set; } public Microsoft.OpenApi.OpenApiSpecVersion SpecificationVersion { get; set; } - public System.Collections.Generic.IList Warnings { get; set; } + public System.Collections.Generic.List Warnings { get; set; } public void AppendDiagnostic(Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnosticToAdd, string? fileNameToAdd = null) { } } public class OpenApiJsonReader : Microsoft.OpenApi.Interfaces.IOpenApiReader @@ -1572,11 +1572,11 @@ namespace Microsoft.OpenApi.Services public class OpenApiUrlTreeNode { public static readonly System.Collections.Generic.IReadOnlyDictionary MermaidNodeStyles; - public System.Collections.Generic.IDictionary> AdditionalData { get; set; } - public System.Collections.Generic.IDictionary Children { get; } + public System.Collections.Generic.Dictionary> AdditionalData { get; set; } + public System.Collections.Generic.Dictionary Children { get; } public bool IsParameter { get; } public string Path { get; set; } - public System.Collections.Generic.IDictionary PathItems { get; } + public System.Collections.Generic.Dictionary PathItems { get; } public string Segment { get; } public void AddAdditionalData(System.Collections.Generic.Dictionary> additionalData) { } public void Attach(Microsoft.OpenApi.Models.OpenApiDocument doc, string label) { } @@ -1623,21 +1623,21 @@ namespace Microsoft.OpenApi.Services public virtual void Visit(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiTag tag) { } public virtual void Visit(Microsoft.OpenApi.Models.References.OpenApiTagReference tag) { } - public virtual void Visit(System.Collections.Generic.IDictionary operations) { } - public virtual void Visit(System.Collections.Generic.IDictionary callbacks) { } - public virtual void Visit(System.Collections.Generic.IDictionary examples) { } - public virtual void Visit(System.Collections.Generic.IDictionary headers) { } - public virtual void Visit(System.Collections.Generic.IDictionary links) { } - public virtual void Visit(System.Collections.Generic.IDictionary webhooks) { } - public virtual void Visit(System.Collections.Generic.IDictionary encodings) { } - public virtual void Visit(System.Collections.Generic.IDictionary content) { } - public virtual void Visit(System.Collections.Generic.IDictionary serverVariables) { } - public virtual void Visit(System.Collections.Generic.IList example) { } - public virtual void Visit(System.Collections.Generic.IList parameters) { } - public virtual void Visit(System.Collections.Generic.IList openApiSecurityRequirements) { } - public virtual void Visit(System.Collections.Generic.IList servers) { } - public virtual void Visit(System.Collections.Generic.ISet openApiTags) { } - public virtual void Visit(System.Collections.Generic.ISet openApiTags) { } + public virtual void Visit(System.Collections.Generic.Dictionary operations) { } + public virtual void Visit(System.Collections.Generic.Dictionary callbacks) { } + public virtual void Visit(System.Collections.Generic.Dictionary examples) { } + public virtual void Visit(System.Collections.Generic.Dictionary headers) { } + public virtual void Visit(System.Collections.Generic.Dictionary links) { } + public virtual void Visit(System.Collections.Generic.Dictionary webhooks) { } + public virtual void Visit(System.Collections.Generic.Dictionary encodings) { } + public virtual void Visit(System.Collections.Generic.Dictionary content) { } + public virtual void Visit(System.Collections.Generic.Dictionary serverVariables) { } + public virtual void Visit(System.Collections.Generic.HashSet openApiTags) { } + public virtual void Visit(System.Collections.Generic.HashSet openApiTags) { } + public virtual void Visit(System.Collections.Generic.List example) { } + public virtual void Visit(System.Collections.Generic.List parameters) { } + public virtual void Visit(System.Collections.Generic.List openApiSecurityRequirements) { } + public virtual void Visit(System.Collections.Generic.List servers) { } public virtual void Visit(System.Text.Json.Nodes.JsonNode node) { } } public class OpenApiWalker @@ -1662,16 +1662,16 @@ namespace Microsoft.OpenApi.Services public class OperationSearch : Microsoft.OpenApi.Services.OpenApiVisitorBase { public OperationSearch(System.Func predicate) { } - public System.Collections.Generic.IList SearchResults { get; } + public System.Collections.Generic.List SearchResults { get; } public override void Visit(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem pathItem) { } - public override void Visit(System.Collections.Generic.IList parameters) { } + public override void Visit(System.Collections.Generic.List parameters) { } } public class SearchResult { public SearchResult() { } public Microsoft.OpenApi.Services.CurrentKeys? CurrentKeys { get; set; } public Microsoft.OpenApi.Models.OpenApiOperation? Operation { get; set; } - public System.Collections.Generic.IList? Parameters { get; set; } + public System.Collections.Generic.List? Parameters { get; set; } } } namespace Microsoft.OpenApi.Validations @@ -1719,15 +1719,15 @@ namespace Microsoft.OpenApi.Validations public override void Visit(Microsoft.OpenApi.Models.OpenApiServer server) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiTag tag) { } - public override void Visit(System.Collections.Generic.IDictionary operations) { } - public override void Visit(System.Collections.Generic.IDictionary callbacks) { } - public override void Visit(System.Collections.Generic.IDictionary examples) { } - public override void Visit(System.Collections.Generic.IDictionary headers) { } - public override void Visit(System.Collections.Generic.IDictionary links) { } - public override void Visit(System.Collections.Generic.IDictionary encodings) { } - public override void Visit(System.Collections.Generic.IDictionary content) { } - public override void Visit(System.Collections.Generic.IDictionary serverVariables) { } - public override void Visit(System.Collections.Generic.IList example) { } + public override void Visit(System.Collections.Generic.Dictionary operations) { } + public override void Visit(System.Collections.Generic.Dictionary callbacks) { } + public override void Visit(System.Collections.Generic.Dictionary examples) { } + public override void Visit(System.Collections.Generic.Dictionary headers) { } + public override void Visit(System.Collections.Generic.Dictionary links) { } + public override void Visit(System.Collections.Generic.Dictionary encodings) { } + public override void Visit(System.Collections.Generic.Dictionary content) { } + public override void Visit(System.Collections.Generic.Dictionary serverVariables) { } + public override void Visit(System.Collections.Generic.List example) { } } public class OpenApiValidatorError : Microsoft.OpenApi.Models.OpenApiError { @@ -1752,23 +1752,23 @@ namespace Microsoft.OpenApi.Validations { public ValidationRuleSet() { } public ValidationRuleSet(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet) { } - public ValidationRuleSet(System.Collections.Generic.IDictionary> rules) { } + public ValidationRuleSet(System.Collections.Generic.Dictionary> rules) { } public int Count { get; } - public System.Collections.Generic.IList Rules { get; } + public System.Collections.Generic.List Rules { get; } public void Add(System.Type key, Microsoft.OpenApi.Validations.ValidationRule rule) { } - public void Add(System.Type key, System.Collections.Generic.IList rules) { } + public void Add(System.Type key, System.Collections.Generic.List rules) { } public void Clear() { } public bool Contains(System.Type key, Microsoft.OpenApi.Validations.ValidationRule rule) { } public bool ContainsKey(System.Type key) { } - public System.Collections.Generic.IList FindRules(System.Type type) { } + public System.Collections.Generic.List FindRules(System.Type type) { } public System.Collections.Generic.IEnumerator GetEnumerator() { } public bool Remove(Microsoft.OpenApi.Validations.ValidationRule rule) { } public bool Remove(System.Type key) { } public void Remove(string ruleName) { } public bool Remove(System.Type key, Microsoft.OpenApi.Validations.ValidationRule rule) { } - public bool TryGetValue(System.Type key, out System.Collections.Generic.IList? rules) { } + public bool TryGetValue(System.Type key, out System.Collections.Generic.List? rules) { } public bool Update(System.Type key, Microsoft.OpenApi.Validations.ValidationRule newRule, Microsoft.OpenApi.Validations.ValidationRule oldRule) { } - public static void AddValidationRules(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet, System.Collections.Generic.IDictionary> rules) { } + public static void AddValidationRules(Microsoft.OpenApi.Validations.ValidationRuleSet ruleSet, System.Collections.Generic.Dictionary> rules) { } public static Microsoft.OpenApi.Validations.ValidationRuleSet GetDefaultRuleSet() { } public static Microsoft.OpenApi.Validations.ValidationRuleSet GetEmptyRuleSet() { } } @@ -1859,7 +1859,7 @@ namespace Microsoft.OpenApi.Validations.Rules public static class OpenApiSchemaRules { public static Microsoft.OpenApi.Validations.ValidationRule ValidateSchemaDiscriminator { get; } - public static bool TraverseSchemaElements(string discriminatorName, System.Collections.Generic.IList? childSchema) { } + public static bool TraverseSchemaElements(string discriminatorName, System.Collections.Generic.List? childSchema) { } public static bool ValidateChildSchemaAgainstDiscriminator(Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema schema, string? discriminatorName) { } } [Microsoft.OpenApi.Validations.Rules.OpenApiRule] @@ -1921,7 +1921,7 @@ namespace Microsoft.OpenApi.Writers public static class OpenApiWriterAnyExtensions { public static void WriteAny(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Text.Json.Nodes.JsonNode? node) { } - public static void WriteExtensions(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Collections.Generic.IDictionary? extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } + public static void WriteExtensions(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, System.Collections.Generic.Dictionary? extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public abstract class OpenApiWriterBase : Microsoft.OpenApi.Writers.IOpenApiWriter { @@ -1968,13 +1968,13 @@ namespace Microsoft.OpenApi.Writers { public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable? elements, System.Action action) { } public static void WriteOptionalCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable? elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary>? elements, System.Action> action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary>? elements, System.Action> action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) { } + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) + public static void WriteOptionalMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } public static void WriteOptionalObject(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T? value, System.Action action) { } public static void WriteProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string? value) { } @@ -1986,8 +1986,8 @@ namespace Microsoft.OpenApi.Writers where T : struct { } public static void WriteRequiredCollection(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } - public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) { } - public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary? elements, System.Action action) + public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) { } + public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.Dictionary? elements, System.Action action) where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { } public static void WriteRequiredObject(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T? value, System.Action action) { } public static void WriteRequiredProperty(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, string? value) { } diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs index 3292a6990..702b4ed12 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs @@ -21,14 +21,14 @@ public class OpenApiUrlTreeNodeTests { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new(), } }, ["/houses"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new(), [HttpMethod.Post] = new() @@ -36,7 +36,7 @@ public class OpenApiUrlTreeNodeTests }, ["/cars"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Post] = new() } @@ -149,7 +149,7 @@ public void AttachPathWorks() var pathItem1 = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -174,7 +174,7 @@ public void AttachPathWorks() var pathItem2 = new OpenApiPathItem { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -241,7 +241,7 @@ public void HasOperationsWorks() ["/houses"] = new OpenApiPathItem(), ["/cars/{car-id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation @@ -269,7 +269,7 @@ public void HasOperationsWorks() { ["/cars/{car-id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { { HttpMethod.Get, new OpenApiOperation diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index 90f88e378..1de888cd3 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs @@ -37,17 +37,17 @@ public void ResponseMustHaveADescription() "/test", new OpenApiPathItem() { - Operations = - { - [HttpMethod.Get] = new() + Operations = new Dictionary { - Responses = + [HttpMethod.Get] = new() { - ["200"] = new OpenApiResponse() + Responses = + { + ["200"] = new OpenApiResponse() + } } } } - } } } }; @@ -74,7 +74,7 @@ public void ServersShouldBeReferencedByIndex() Title = "foo", Version = "1.2.2" }, - Servers = new List { + Servers = [ new() { Url = "http://example.org" @@ -82,7 +82,7 @@ public void ServersShouldBeReferencedByIndex() new() { }, - }, + ], Paths = new() }; @@ -131,7 +131,10 @@ public void ValidateCustomExtension() var extensionNode = JsonSerializer.Serialize(fooExtension); var jsonNode = JsonNode.Parse(extensionNode); - openApiDocument.Info.Extensions.Add("x-foo", new OpenApiAny(jsonNode)); + openApiDocument.Info.Extensions = new Dictionary + { + { "x-foo", new OpenApiAny(jsonNode) } + }; var validator = new OpenApiValidator(ruleset); var walker = new OpenApiWalker(validator); diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs index 6c96c3d97..b70eea7bc 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiHeaderValidationTests.cs @@ -57,7 +57,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() Type = JsonSchemaType.Integer } }, - Examples = + Examples = new Dictionary { ["example0"] = new OpenApiExample() { diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs index 05b4bb62c..17d3bdd54 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text.Json.Nodes; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Services; using Xunit; @@ -55,8 +56,8 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() Type = JsonSchemaType.Integer, } }, - Examples = - { + Examples = new Dictionary + { ["example0"] = new OpenApiExample() { Value = "1", diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiOAuthFlowValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiOAuthFlowValidationTests.cs index ad8e5f387..0c7778215 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiOAuthFlowValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiOAuthFlowValidationTests.cs @@ -19,6 +19,8 @@ public void ValidateFixedFieldsIsRequiredInResponse() // Arrange var authorizationUrlError = string.Format(SRResource.Validation_FieldIsRequired, "authorizationUrl", "OAuth Flow"); var tokenUrlError = string.Format(SRResource.Validation_FieldIsRequired, "tokenUrl", "OAuth Flow"); + var scopesError = string.Format(SRResource.Validation_FieldIsRequired, "scopes", "OAuth Flow"); + IEnumerable errors; var oAuthFlow = new OpenApiOAuthFlow(); @@ -33,8 +35,8 @@ public void ValidateFixedFieldsIsRequiredInResponse() // Assert Assert.False(result); Assert.NotNull(errors); - Assert.Equal(2, errors.Count()); - Assert.Equal(new[] { authorizationUrlError, tokenUrlError }, errors.Select(e => e.Message)); + Assert.Equal(3, errors.Count()); + Assert.Equal(new[] { authorizationUrlError, tokenUrlError, scopesError }, errors.Select(e => e.Message)); } } } diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs index 721445e23..6142bd082 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiParameterValidationTests.cs @@ -107,8 +107,8 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema() Type = JsonSchemaType.Integer, } }, - Examples = - { + Examples = new Dictionary + { ["example0"] = new OpenApiExample() { Value = "1", diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs index 1828ca470..0fb23578b 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs @@ -29,7 +29,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() var document = new OpenApiDocument(); document.Components = new() { - Schemas = new Dictionary() + Schemas = new() { ["test"] = sharedSchema } @@ -39,7 +39,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { @@ -47,7 +47,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() { ["200"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -62,7 +62,7 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() }; // Act - var rules = new Dictionary>() + var rules = new Dictionary>() { { typeof(IOpenApiSchema), new List() { new AlwaysFailRule() } @@ -93,7 +93,7 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { @@ -101,7 +101,7 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() { ["200"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -116,7 +116,7 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() }; // Act - var rules = new Dictionary>() + var rules = new Dictionary>() { { typeof(OpenApiSchema), new List() { new AlwaysFailRule() } diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index d8820defc..f0c772473 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -73,8 +73,8 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema() IEnumerable warnings; var schema = new OpenApiSchema() { - Enum = - { + Enum = + [ new OpenApiAny("1").Node, new OpenApiAny(new JsonObject() { @@ -88,7 +88,7 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema() ["x"] = 4, ["y"] = 40, }).Node - }, + ], Type = JsonSchemaType.Object, AdditionalProperties = new OpenApiSchema() { @@ -115,7 +115,7 @@ public void ValidateDefaultShouldNotHaveDataTypeMismatchForComplexSchema() var schema = new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = + Properties = new Dictionary { ["property1"] = new OpenApiSchema() { @@ -187,7 +187,8 @@ public void ValidateSchemaRequiredFieldListMustContainThePropertySpecifiedInTheD { var components = new OpenApiComponents { - Schemas = { + Schemas = new Dictionary + { { "schema1", new OpenApiSchema @@ -219,7 +220,7 @@ public void ValidateOneOfSchemaPropertyNameContainsPropertySpecifiedInTheDiscrim // Arrange var components = new OpenApiComponents { - Schemas = + Schemas = new Dictionary { { "Person", @@ -230,11 +231,11 @@ public void ValidateOneOfSchemaPropertyNameContainsPropertySpecifiedInTheDiscrim { PropertyName = "type" }, - OneOf = new List - { + OneOf = + [ new OpenApiSchema() { - Properties = + Properties = new Dictionary { { "type", @@ -245,7 +246,7 @@ public void ValidateOneOfSchemaPropertyNameContainsPropertySpecifiedInTheDiscrim } }, } - }, + ], } } } diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs index d956e2cd0..9824b17f6 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs @@ -42,7 +42,10 @@ public void ValidateExtensionNameStartsWithXDashInTag() { Name = "tag" }; - tag.Extensions.Add("tagExt", new OpenApiAny("value")); + tag.Extensions = new Dictionary + { + { "tagExt", new OpenApiAny("value") } + }; // Act var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); diff --git a/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs b/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs index 6b4a920cf..48ac1f105 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs @@ -22,15 +22,15 @@ public class ValidationRuleSetTests private readonly ValidationRule _parameterValidationRule = new ValidationRule(nameof(_parameterValidationRule), (context, item) => { }); - private readonly IDictionary> _rulesDictionary; + private readonly Dictionary> _rulesDictionary; public ValidationRuleSetTests() { - _rulesDictionary = new Dictionary>() + _rulesDictionary = new Dictionary>() { - {typeof(OpenApiContact), new List { _contactValidationRule } }, - {typeof(OpenApiHeader), new List { _headerValidationRule } }, - {typeof(OpenApiParameter), new List { _parameterValidationRule } } + {typeof(OpenApiContact), [_contactValidationRule] }, + {typeof(OpenApiHeader), [_headerValidationRule] }, + {typeof(OpenApiParameter), [_parameterValidationRule] } }; } @@ -69,7 +69,7 @@ public void RemoveValidatioRuleGivenTheValidationRuleWorks() // Act and Assert Assert.True(ruleSet.Remove(_contactValidationRule)); - Assert.False(ruleSet.Rules.Contains(_contactValidationRule)); + Assert.DoesNotContain(_contactValidationRule, ruleSet.Rules); Assert.False(ruleSet.Remove(_contactValidationRule)); // rule already removed } @@ -87,9 +87,9 @@ public void RemoveValidationRuleGivenTheKeyAndValidationRuleWorks() var rules = ruleSet.Rules; // Assert - Assert.False(rules.Contains(_contactValidationRule)); - Assert.True(rules.Contains(_headerValidationRule)); - Assert.True(rules.Contains(_parameterValidationRule)); + Assert.DoesNotContain(_contactValidationRule, rules); + Assert.Contains(_headerValidationRule, rules); + Assert.Contains(_parameterValidationRule, rules); } [Fact] @@ -98,9 +98,9 @@ public void RemoveRulesGivenAKeyWorks() // Arrange var ruleSet = new ValidationRuleSet(_rulesDictionary); var responseValidationRule = new ValidationRule("ValidateResponses", (context, item) => { }); - ruleSet.Add(typeof(OpenApiResponse), new List { responseValidationRule }); + ruleSet.Add(typeof(OpenApiResponse), [responseValidationRule]); Assert.True(ruleSet.ContainsKey(typeof(OpenApiResponse))); - Assert.True(ruleSet.Rules.Contains(responseValidationRule)); // guard + Assert.Contains(responseValidationRule, ruleSet.Rules); // guard // Act ruleSet.Remove(typeof(OpenApiResponse)); @@ -119,11 +119,11 @@ public void AddNewValidationRuleWorks() var pathsValidationRule = new ValidationRule("ValidatePaths", (context, item) => { }); // Act - ruleSet.Add(typeof(OpenApiResponse), new List { responseValidationRule }); - ruleSet.Add(typeof(OpenApiTag), new List { tagValidationRule }); - var rulesDictionary = new Dictionary>() + ruleSet.Add(typeof(OpenApiResponse), [responseValidationRule]); + ruleSet.Add(typeof(OpenApiTag), [tagValidationRule]); + var rulesDictionary = new Dictionary>() { - {typeof(OpenApiPaths), new List { pathsValidationRule } } + {typeof(OpenApiPaths), [pathsValidationRule] } }; ValidationRuleSet.AddValidationRules(ruleSet, rulesDictionary); @@ -132,9 +132,9 @@ public void AddNewValidationRuleWorks() Assert.True(ruleSet.ContainsKey(typeof(OpenApiResponse))); Assert.True(ruleSet.ContainsKey(typeof(OpenApiTag))); Assert.True(ruleSet.ContainsKey(typeof(OpenApiPaths))); - Assert.True(ruleSet.Rules.Contains(responseValidationRule)); - Assert.True(ruleSet.Rules.Contains(tagValidationRule)); - Assert.True(ruleSet.Rules.Contains(pathsValidationRule)); + Assert.Contains(responseValidationRule, ruleSet.Rules); + Assert.Contains(tagValidationRule, ruleSet.Rules); + Assert.Contains(pathsValidationRule, ruleSet.Rules); } [Fact] @@ -143,7 +143,7 @@ public void UpdateValidationRuleWorks() // Arrange var ruleSet = new ValidationRuleSet(_rulesDictionary); var responseValidationRule = new ValidationRule("ValidateResponses", (context, item) => { }); - ruleSet.Add(typeof(OpenApiResponse), new List { responseValidationRule }); + ruleSet.Add(typeof(OpenApiResponse), [responseValidationRule]); // Act var pathsValidationRule = new ValidationRule("ValidatePaths", (context, item) => { }); @@ -165,7 +165,7 @@ public void TryGetValueWorks() // Assert Assert.True(validationRules.Any()); - Assert.True(validationRules.Contains(_contactValidationRule)); + Assert.Contains(_contactValidationRule, validationRules); } [Fact] @@ -175,10 +175,10 @@ public void ClearAllRulesWorks() var ruleSet = new ValidationRuleSet(); var tagValidationRule = new ValidationRule("ValidateTags", (context, item) => { }); var pathsValidationRule = new ValidationRule("ValidatePaths", (context, item) => { }); - var rulesDictionary = new Dictionary>() + var rulesDictionary = new Dictionary>() { - {typeof(OpenApiPaths), new List { pathsValidationRule } }, - {typeof(OpenApiTag), new List { tagValidationRule } } + {typeof(OpenApiPaths), [pathsValidationRule] }, + {typeof(OpenApiTag), [tagValidationRule] } }; ValidationRuleSet.AddValidationRules(ruleSet, rulesDictionary); diff --git a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs index ee7252d42..030e60581 100644 --- a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs @@ -24,28 +24,28 @@ public void ExpectedVirtualsInvolved() visitor.Visit(default(OpenApiInfo)); visitor.Visit(default(OpenApiContact)); visitor.Visit(default(OpenApiLicense)); - visitor.Visit(default(IList)); + visitor.Visit(default(List)); visitor.Visit(default(OpenApiServer)); visitor.Visit(default(OpenApiPaths)); visitor.Visit(default(IOpenApiPathItem)); visitor.Visit(default(OpenApiServerVariable)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(OpenApiOperation)); - visitor.Visit(default(IList)); + visitor.Visit(default(List)); visitor.Visit(default(IOpenApiParameter)); visitor.Visit(default(IOpenApiRequestBody)); - visitor.Visit(default(IDictionary)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(Dictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(IOpenApiResponse)); visitor.Visit(default(OpenApiResponses)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(OpenApiMediaType)); visitor.Visit(default(OpenApiEncoding)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(OpenApiComponents)); visitor.Visit(default(OpenApiExternalDocs)); visitor.Visit(default(IOpenApiSchema)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(IOpenApiLink)); visitor.Visit(default(IOpenApiCallback)); visitor.Visit(default(OpenApiTag)); @@ -54,13 +54,13 @@ public void ExpectedVirtualsInvolved() visitor.Visit(default(OpenApiSecurityRequirement)); visitor.Visit(default(IOpenApiSecurityScheme)); visitor.Visit(default(IOpenApiExample)); - visitor.Visit(default(ISet)); - visitor.Visit(default(IList)); + visitor.Visit(default(HashSet)); + visitor.Visit(default(List)); visitor.Visit(default(IOpenApiExtensible)); visitor.Visit(default(IOpenApiExtension)); - visitor.Visit(default(IList)); - visitor.Visit(default(IDictionary)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(List)); + visitor.Visit(default(Dictionary)); + visitor.Visit(default(Dictionary)); visitor.Visit(default(IOpenApiReferenceHolder)); visitor.Exit(); Assert.True(42 < ((TestVisitor)visitor).CallStack.Count); @@ -113,7 +113,7 @@ public override void Visit(OpenApiLicense license) base.Visit(license); } - public override void Visit(IList servers) + public override void Visit(List servers) { EncodeCall(); base.Visit(servers); @@ -143,7 +143,7 @@ public override void Visit(OpenApiServerVariable serverVariable) base.Visit(serverVariable); } - public override void Visit(IDictionary operations) + public override void Visit(Dictionary operations) { EncodeCall(); base.Visit(operations); @@ -155,7 +155,7 @@ public override void Visit(OpenApiOperation operation) base.Visit(operation); } - public override void Visit(IList parameters) + public override void Visit(List parameters) { EncodeCall(); base.Visit(parameters); @@ -173,13 +173,13 @@ public override void Visit(IOpenApiRequestBody requestBody) base.Visit(requestBody); } - public override void Visit(IDictionary headers) + public override void Visit(Dictionary headers) { EncodeCall(); base.Visit(headers); } - public override void Visit(IDictionary callbacks) + public override void Visit(Dictionary callbacks) { EncodeCall(); base.Visit(callbacks); @@ -197,7 +197,7 @@ public override void Visit(OpenApiResponses response) base.Visit(response); } - public override void Visit(IDictionary content) + public override void Visit(Dictionary content) { EncodeCall(); base.Visit(content); @@ -215,7 +215,7 @@ public override void Visit(OpenApiEncoding encoding) base.Visit(encoding); } - public override void Visit(IDictionary examples) + public override void Visit(Dictionary examples) { EncodeCall(); base.Visit(examples); @@ -239,7 +239,7 @@ public override void Visit(IOpenApiSchema schema) base.Visit(schema); } - public override void Visit(IDictionary links) + public override void Visit(Dictionary links) { EncodeCall(); base.Visit(links); @@ -293,13 +293,13 @@ public override void Visit(IOpenApiExample example) base.Visit(example); } - public override void Visit(ISet openApiTags) + public override void Visit(HashSet openApiTags) { EncodeCall(); base.Visit(openApiTags); } - public override void Visit(IList openApiSecurityRequirements) + public override void Visit(List openApiSecurityRequirements) { EncodeCall(); base.Visit(openApiSecurityRequirements); @@ -317,19 +317,19 @@ public override void Visit(IOpenApiExtension openApiExtension) base.Visit(openApiExtension); } - public override void Visit(IList example) + public override void Visit(List example) { EncodeCall(); base.Visit(example); } - public override void Visit(IDictionary serverVariables) + public override void Visit(Dictionary serverVariables) { EncodeCall(); base.Visit(serverVariables); } - public override void Visit(IDictionary encodings) + public override void Visit(Dictionary encodings) { EncodeCall(); base.Visit(encodings); diff --git a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs index 6af474e22..01f3c223b 100644 --- a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs @@ -37,11 +37,11 @@ public void LocateTopLevelArrayItems() { var doc = new OpenApiDocument { - Servers = new List - { + Servers = + [ new(), new() - }, + ], Tags = new HashSet { new() @@ -68,7 +68,7 @@ public void LocatePathOperationContentSchema() var doc = new OpenApiDocument(); doc.Paths.Add("/test", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { @@ -76,7 +76,7 @@ public void LocatePathOperationContentSchema() { ["200"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { @@ -119,7 +119,7 @@ public void WalkDOMWithCycles() var loopySchema = new OpenApiSchema { Type = JsonSchemaType.Object, - Properties = new Dictionary + Properties = new() { ["name"] = new OpenApiSchema() { Type = JsonSchemaType.String } } @@ -131,7 +131,7 @@ public void WalkDOMWithCycles() { Components = new() { - Schemas = new Dictionary + Schemas = new() { ["loopy"] = loopySchema } @@ -162,7 +162,7 @@ public void LocateReferences() var derivedSchema = new OpenApiSchema { - AnyOf = new List { new OpenApiSchemaReference("base") }, + AnyOf = [new OpenApiSchemaReference("base")], }; var testHeader = new OpenApiHeader() @@ -177,7 +177,7 @@ public void LocateReferences() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new() { [HttpMethod.Get] = new() { @@ -185,14 +185,14 @@ public void LocateReferences() { ["200"] = new OpenApiResponse() { - Content = new Dictionary + Content = new() { ["application/json"] = new() { Schema = new OpenApiSchemaReference("derived") } }, - Headers = + Headers = new Dictionary { ["test-header"] = testHeaderReference } @@ -204,12 +204,12 @@ public void LocateReferences() }, Components = new() { - Schemas = new Dictionary + Schemas = new() { ["derived"] = derivedSchema, ["base"] = baseSchema, }, - Headers = + Headers = new Dictionary { ["test-header"] = testHeader }, @@ -285,7 +285,7 @@ public override void Visit(IOpenApiReferenceHolder referenceable) { Locations.Add("referenceAt: " + this.PathString); } - public override void Visit(IDictionary content) + public override void Visit(Dictionary content) { Locations.Add(this.PathString); } @@ -301,12 +301,12 @@ public override void Visit(IOpenApiSchema schema) Locations.Add(this.PathString); } - public override void Visit(ISet openApiTags) + public override void Visit(HashSet openApiTags) { Locations.Add(this.PathString); } - public override void Visit(IList servers) + public override void Visit(List servers) { Locations.Add(this.PathString); } @@ -315,7 +315,7 @@ public override void Visit(OpenApiServer server) { Locations.Add(this.PathString); } - public override void Visit(ISet openApiTags) + public override void Visit(HashSet openApiTags) { Locations.Add(this.PathString); } diff --git a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs index 167d5e359..17dab923b 100644 --- a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiReferencableTests.cs @@ -7,6 +7,7 @@ using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Properties; using Xunit; @@ -20,7 +21,7 @@ public class OpenApiReferencableTests private static readonly OpenApiHeader _headerFragment = new() { Schema = new OpenApiSchema(), - Examples = + Examples = new Dictionary { { "example1", new OpenApiExample() } } @@ -28,7 +29,7 @@ public class OpenApiReferencableTests private static readonly OpenApiParameter _parameterFragment = new() { Schema = new OpenApiSchema(), - Examples = + Examples = new Dictionary { { "example1", new OpenApiExample() } } @@ -36,32 +37,31 @@ public class OpenApiReferencableTests private static readonly OpenApiRequestBody _requestBodyFragment = new(); private static readonly OpenApiResponse _responseFragment = new() { - Headers = + Headers = new Dictionary { { "header1", new OpenApiHeader() } }, - Links = + Links = new Dictionary { { "link1", new OpenApiLink() } } }; private static readonly OpenApiSecurityScheme _securitySchemeFragment = new OpenApiSecurityScheme(); public static IEnumerable ResolveReferenceCanResolveValidJsonPointersTestData => - new List - { - new object[] { _callbackFragment, "/", _callbackFragment }, - new object[] { _exampleFragment, "/", _exampleFragment }, - new object[] { _linkFragment, "/", _linkFragment }, - new object[] { _headerFragment, "/", _headerFragment }, - new object[] { _headerFragment, "/examples/example1", _headerFragment.Examples["example1"] }, - new object[] { _parameterFragment, "/", _parameterFragment }, - new object[] { _parameterFragment, "/examples/example1", _parameterFragment.Examples["example1"] }, - new object[] { _requestBodyFragment, "/", _requestBodyFragment }, - new object[] { _responseFragment, "/", _responseFragment }, - new object[] { _responseFragment, "/headers/header1", _responseFragment.Headers["header1"] }, - new object[] { _responseFragment, "/links/link1", _responseFragment.Links["link1"] }, - new object[] { _securitySchemeFragment, "/", _securitySchemeFragment}, - }; + [ + [_callbackFragment, "/", _callbackFragment], + [_exampleFragment, "/", _exampleFragment], + [_linkFragment, "/", _linkFragment], + [_headerFragment, "/", _headerFragment], + [_headerFragment, "/examples/example1", _headerFragment.Examples["example1"]], + [_parameterFragment, "/", _parameterFragment], + [_parameterFragment, "/examples/example1", _parameterFragment.Examples["example1"]], + [_requestBodyFragment, "/", _requestBodyFragment], + [_responseFragment, "/", _responseFragment], + [_responseFragment, "/headers/header1", _responseFragment.Headers["header1"]], + [_responseFragment, "/links/link1", _responseFragment.Links["link1"]], + [_securitySchemeFragment, "/", _securitySchemeFragment], + ]; [Theory] [MemberData(nameof(ResolveReferenceCanResolveValidJsonPointersTestData))] @@ -78,25 +78,24 @@ public void ResolveReferenceCanResolveValidJsonPointers( } public static IEnumerable ResolveReferenceShouldThrowOnInvalidReferenceIdTestData => - new List - { - new object[] { _callbackFragment, "/a" }, - new object[] { _headerFragment, "/a" }, - new object[] { _headerFragment, "/examples" }, - new object[] { _headerFragment, "/examples/" }, - new object[] { _headerFragment, "/examples/a" }, - new object[] { _parameterFragment, "/a" }, - new object[] { _parameterFragment, "/examples" }, - new object[] { _parameterFragment, "/examples/" }, - new object[] { _parameterFragment, "/examples/a" }, - new object[] { _responseFragment, "/a" }, - new object[] { _responseFragment, "/headers" }, - new object[] { _responseFragment, "/headers/" }, - new object[] { _responseFragment, "/headers/a" }, - new object[] { _responseFragment, "/content" }, - new object[] { _responseFragment, "/content/" }, - new object[] { _responseFragment, "/content/a" } - }; + [ + [_callbackFragment, "/a"], + [_headerFragment, "/a"], + [_headerFragment, "/examples"], + [_headerFragment, "/examples/"], + [_headerFragment, "/examples/a"], + [_parameterFragment, "/a"], + [_parameterFragment, "/examples"], + [_parameterFragment, "/examples/"], + [_parameterFragment, "/examples/a"], + [_responseFragment, "/a"], + [_responseFragment, "/headers"], + [_responseFragment, "/headers/"], + [_responseFragment, "/headers/a"], + [_responseFragment, "/content"], + [_responseFragment, "/content/"], + [_responseFragment, "/content/a"] + ]; [Theory] [MemberData(nameof(ResolveReferenceShouldThrowOnInvalidReferenceIdTestData))] diff --git a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs index 02c1cf07c..ba66aeedf 100644 --- a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs @@ -6,6 +6,7 @@ using System.Net.Http; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Services; using Xunit; @@ -28,7 +29,7 @@ public void OpenApiWorkspacesCanAddComponentsFromAnotherDocument() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary() + Operations = new() { [HttpMethod.Get] = new OpenApiOperation() { @@ -36,7 +37,7 @@ public void OpenApiWorkspacesCanAddComponentsFromAnotherDocument() { ["200"] = new OpenApiResponse() { - Content = new Dictionary() + Content = new() { ["application/json"] = new OpenApiMediaType() { @@ -55,7 +56,8 @@ public void OpenApiWorkspacesCanAddComponentsFromAnotherDocument() { Components = new OpenApiComponents() { - Schemas = { + Schemas = new() + { ["test"] = testSchema } } @@ -108,7 +110,7 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragmentsWithJsonPoin var workspace = new OpenApiWorkspace(); var responseFragment = new OpenApiResponse { - Headers = + Headers = new Dictionary { { "header1", new OpenApiHeader() } } @@ -130,7 +132,7 @@ private static OpenApiDocument CreateCommonDocument() { Components = new() { - Schemas = + Schemas = new() { ["test"] = new OpenApiSchema() { diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index 54fb8cfb6..fb149b5ec 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs @@ -75,10 +75,9 @@ public async Task WriteStringListAsJsonShouldMatchExpected(string[] stringValues public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesSimple() { return - from input in new IDictionary[] { + from input in new Dictionary[] { // Simple map - new Dictionary - { + new() { ["property1"] = "value1", ["property2"] = "value2", ["property3"] = "value3", @@ -86,8 +85,7 @@ public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesSi }, // Simple map with duplicate values - new Dictionary - { + new() { ["property1"] = "value1", ["property2"] = "value1", ["property3"] = "value1", @@ -101,10 +99,9 @@ from shouldBeTerse in shouldProduceTerseOutputValues public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesComplex() { return - from input in new IDictionary[] { + from input in new Dictionary[] { // Empty map and empty list - new Dictionary - { + new() { ["property1"] = new Dictionary(), ["property2"] = new List(), ["property3"] = new List @@ -115,8 +112,7 @@ public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesCo }, // Number, boolean, and null handling - new Dictionary - { + new() { ["property1"] = "10.0", ["property2"] = "10", ["property3"] = "-5", @@ -131,16 +127,14 @@ public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesCo }, // DateTime - new Dictionary - { + new() { ["property1"] = new DateTime(1970, 01, 01), ["property2"] = new DateTimeOffset(new(1970, 01, 01)), ["property3"] = new DateTime(2018, 04, 03), }, // Nested map - new Dictionary - { + new() { ["property1"] = new Dictionary { ["innerProperty1"] = "innerValue1" @@ -154,8 +148,7 @@ public static IEnumerable WriteMapAsJsonShouldMatchExpectedTestCasesCo }, // Nested map and list - new Dictionary - { + new() { ["property1"] = new Dictionary(), ["property2"] = new List(), ["property3"] = new List @@ -194,7 +187,7 @@ private void WriteValueRecursive(OpenApiJsonWriter writer, object value) writer.WriteValue(value); } else if (value.GetType().IsGenericType && - (typeof(IDictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()) || + (typeof(Dictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()) || typeof(Dictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()))) { writer.WriteStartObject(); @@ -221,7 +214,7 @@ private void WriteValueRecursive(OpenApiJsonWriter writer, object value) [Theory] [MemberData(nameof(WriteMapAsJsonShouldMatchExpectedTestCasesSimple))] [MemberData(nameof(WriteMapAsJsonShouldMatchExpectedTestCasesComplex))] - public void WriteMapAsJsonShouldMatchExpected(IDictionary inputMap, bool produceTerseOutput) + public void WriteMapAsJsonShouldMatchExpected(Dictionary inputMap, bool produceTerseOutput) { // Arrange using var outputString = new StringWriter(CultureInfo.InvariantCulture); @@ -325,12 +318,12 @@ public void OpenApiJsonWriterOutputsValidJsonValueWhenSchemaHasNanOrInfinityValu // Arrange var schema = new OpenApiSchema { - Enum = new List - { + Enum = + [ new OpenApiAny("NaN").Node, new OpenApiAny("Infinity").Node, new OpenApiAny("-Infinity").Node - } + ] }; // Act diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs index 1f4d45e81..dd5608f53 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs @@ -9,6 +9,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Writers; using Xunit; @@ -276,7 +277,7 @@ private void WriteValueRecursive(OpenApiYamlWriter writer, object value) writer.WriteValue(value); } else if (value.GetType().IsGenericType && - (typeof(IDictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()) || + (typeof(Dictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()) || typeof(Dictionary<,>).IsAssignableFrom(value.GetType().GetGenericTypeDefinition()))) { writer.WriteStartObject(); @@ -303,7 +304,7 @@ private void WriteValueRecursive(OpenApiYamlWriter writer, object value) [Theory] [MemberData(nameof(WriteMapAsYamlShouldMatchExpectedTestCasesSimple))] [MemberData(nameof(WriteMapAsYamlShouldMatchExpectedTestCasesComplex))] - public void WriteMapAsYamlShouldMatchExpected(IDictionary inputMap, string expectedYaml) + public void WriteMapAsYamlShouldMatchExpected(Dictionary inputMap, string expectedYaml) { // Arrange var outputString = new StringWriter(CultureInfo.InvariantCulture); @@ -456,14 +457,16 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() { ["/"] = new OpenApiPathItem() { - Operations = { + Operations = new() + { [HttpMethod.Get] = new() { Responses = { ["200"] = new OpenApiResponse() { Description = "OK", - Content = { + Content = new() + { ["application/json"] = new() { Schema = new OpenApiSchemaReference("thing") @@ -477,8 +480,10 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() }, Components = new() { - Schemas = { - ["thing"] = thingSchema} + Schemas = new() + { + ["thing"] = thingSchema + } } }; doc.RegisterComponents();