diff --git a/src/Microsoft.OpenApi/Any/OpenApiAny.cs b/src/Microsoft.OpenApi/Any/OpenApiAny.cs index 54bddf326..3b33140b7 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiAny.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiAny.cs @@ -37,5 +37,17 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) { writer.WriteAny(Node); } + + /// + /// Implicit conversion from JsonNode to an OpenApiAny. + /// + /// + public static implicit operator OpenApiAny(JsonNode jsonNode) => new(jsonNode); + + /// + /// Implicit conversion from OpenApiAny to a JsonNode. + /// + /// + public static implicit operator JsonNode(OpenApiAny openApiAny) => openApiAny.Node; } } diff --git a/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs new file mode 100644 index 000000000..236e3c07e --- /dev/null +++ b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using System.Text.Json.Nodes; +using Microsoft.OpenApi.Interfaces; + +namespace Microsoft.OpenApi.Any +{ + /// + /// A dictionary of OpenApi extensions. + /// + public class OpenApiExtensionDictionary : Dictionary + { + /// + /// Initializes a copy of object + /// + /// + public OpenApiExtensionDictionary(OpenApiExtensionDictionary extensions) : base(dictionary: extensions) { } + + /// + /// Parameterless constructor + /// + public OpenApiExtensionDictionary() { } + + /// + /// Override the base class indexer to return OpenApiAny. + /// + /// + /// + public new OpenApiAny this[string key] + { + get => (OpenApiAny)base[key]; + set => base[key] = ConvertIfJsonNode(value)!; + } + + /// + /// Adds an extension to the dictionary. + /// + /// + /// + public void Add(string key, object value) + { + base.Add(key, ConvertIfJsonNode(value)!); + } + + private static IOpenApiExtension? ConvertIfJsonNode(object? value) + { + return value switch + { + IOpenApiExtension extension => extension, + JsonNode node => (OpenApiAny)node, + _ => null + }; + } + } +} diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs index bea3597a6..40bc4528f 100644 --- a/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiExtensibleExtensions.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. using System; -using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -32,9 +32,8 @@ public static void AddExtension(this T element, string name, IOpenApiExtensio { throw new OpenApiException(string.Format(SRResource.ExtensionFieldNameMustBeginWithXDash, name)); } - element.Extensions ??= []; - element.Extensions[name] = Utils.CheckArgumentNull(any); + element.Extensions[name] = (OpenApiAny)Utils.CheckArgumentNull(any); } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs index be7796a24..65c7d9379 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiExtensible.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using Microsoft.OpenApi.Any; namespace Microsoft.OpenApi.Interfaces { @@ -13,6 +14,6 @@ public interface IOpenApiExtensible : IOpenApiElement /// /// Specification extensions. /// - Dictionary? Extensions { get; set; } + OpenApiExtensionDictionary? Extensions { get; set; } } } diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs index fc3d19cfa..d98e6b85c 100644 --- a/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReadOnlyExtensible.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +using Microsoft.OpenApi.Any; namespace Microsoft.OpenApi.Interfaces; @@ -10,6 +13,5 @@ public interface IOpenApiReadOnlyExtensible /// /// Specification extensions. /// - Dictionary? Extensions { get; } - + OpenApiExtensionDictionary? Extensions { get; } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 8bd90ed7f..caa6599ac 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -22,7 +24,7 @@ public class OpenApiCallback : IOpenApiExtensible, IOpenApiCallback /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -36,7 +38,7 @@ internal OpenApiCallback(IOpenApiCallback callback) { Utils.CheckArgumentNull(callback); PathItems = callback?.PathItems != null ? new(callback.PathItems) : null; - Extensions = callback?.Extensions != null ? new Dictionary(callback.Extensions) : null; + Extensions = callback?.Extensions != null ? new OpenApiExtensionDictionary(callback.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs index fb0129bec..b878f6d20 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -69,7 +70,7 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -91,7 +92,7 @@ public OpenApiComponents(OpenApiComponents? components) Links = components?.Links != null ? new Dictionary(components.Links) : null; Callbacks = components?.Callbacks != null ? new Dictionary(components.Callbacks) : null; PathItems = components?.PathItems != null ? new Dictionary(components.PathItems) : null; - Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null; + Extensions = components?.Extensions != null ? new OpenApiExtensionDictionary(components.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiContact.cs b/src/Microsoft.OpenApi/Models/OpenApiContact.cs index b6ed82171..70df5ae42 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiContact.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiContact.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -32,7 +33,7 @@ public class OpenApiContact : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -47,7 +48,7 @@ public OpenApiContact(OpenApiContact contact) Name = contact?.Name ?? Name; Url = contact?.Url != null ? new Uri(contact.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; Email = contact?.Email ?? Email; - Extensions = contact?.Extensions != null ? new Dictionary(contact.Extensions) : null; + Extensions = contact?.Extensions != null ? new OpenApiExtensionDictionary(contact.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs index 8ad465241..1da093c48 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Writers; @@ -26,7 +27,7 @@ public class OpenApiDiscriminator : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -40,7 +41,7 @@ public OpenApiDiscriminator(OpenApiDiscriminator discriminator) { PropertyName = discriminator?.PropertyName ?? PropertyName; Mapping = discriminator?.Mapping != null ? new Dictionary(discriminator.Mapping) : null; - Extensions = discriminator?.Extensions != null ? new Dictionary(discriminator.Extensions) : null; + Extensions = discriminator?.Extensions != null ? new OpenApiExtensionDictionary(discriminator.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs index c5ac5f759..6561b71de 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -103,7 +104,7 @@ public HashSet? Tags /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// public Dictionary? Metadata { get; set; } @@ -139,7 +140,7 @@ public OpenApiDocument(OpenApiDocument? document) 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; + Extensions = document?.Extensions != null ? new OpenApiExtensionDictionary(document.Extensions) : null; Metadata = document?.Metadata != null ? new Dictionary(document.Metadata) : null; BaseUri = document?.BaseUri != null ? document.BaseUri : new(OpenApiConstants.BaseRegistryUri + Guid.NewGuid()); } diff --git a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs index cc9340317..58af7e45a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiEncoding.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -52,7 +53,7 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -69,7 +70,7 @@ public OpenApiEncoding(OpenApiEncoding encoding) Style = encoding?.Style ?? Style; Explode = encoding?.Explode ?? Explode; AllowReserved = encoding?.AllowReserved ?? AllowReserved; - Extensions = encoding?.Extensions != null ? new Dictionary(encoding.Extensions) : null; + Extensions = encoding?.Extensions != null ? new OpenApiExtensionDictionary(encoding.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExample.cs b/src/Microsoft.OpenApi/Models/OpenApiExample.cs index 6ffb26f2e..09a5e14da 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExample.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExample.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -28,7 +29,7 @@ public class OpenApiExample : IOpenApiExtensible, IOpenApiExample public JsonNode? Value { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -46,7 +47,7 @@ internal OpenApiExample(IOpenApiExample example) Description = example.Description ?? Description; Value = example.Value != null ? JsonNodeCloneHelper.Clone(example.Value) : null; ExternalValue = example.ExternalValue ?? ExternalValue; - Extensions = example.Extensions != null ? new Dictionary(example.Extensions) : null; + Extensions = example.Extensions != null ? new OpenApiExtensionDictionary(example.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs index 7e4f9f686..d211685f7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -28,15 +29,15 @@ protected OpenApiExtensibleDictionary():this([]) { } /// The dictionary of . protected OpenApiExtensibleDictionary( Dictionary dictionary, - Dictionary? extensions = null) : base(dictionary is null ? [] : dictionary) + OpenApiExtensionDictionary? extensions = null) : base(dictionary is null ? [] : dictionary) { - Extensions = extensions != null ? new Dictionary(extensions) : []; + Extensions = extensions != null ? new OpenApiExtensionDictionary(extensions) : []; } /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs index 381ee53bb..34080f1fb 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiExternalDocs.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -26,7 +27,7 @@ public class OpenApiExternalDocs : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -40,7 +41,7 @@ public OpenApiExternalDocs(OpenApiExternalDocs externalDocs) { Description = externalDocs?.Description ?? Description; Url = externalDocs?.Url != null ? new Uri(externalDocs.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = externalDocs?.Extensions != null ? new Dictionary(externalDocs.Extensions) : null; + Extensions = externalDocs?.Extensions != null ? new OpenApiExtensionDictionary(externalDocs.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs index 62bb09b89..25c7cd6b6 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; @@ -53,7 +54,7 @@ public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible public Dictionary? Content { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -77,7 +78,7 @@ internal OpenApiHeader(IOpenApiHeader header) Example = header.Example != null ? JsonNodeCloneHelper.Clone(header.Example) : null; Examples = header.Examples != null ? new Dictionary(header.Examples) : null; Content = header.Content != null ? new Dictionary(header.Content) : null; - Extensions = header.Extensions != null ? new Dictionary(header.Extensions) : null; + Extensions = header.Extensions != null ? new OpenApiExtensionDictionary(header.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs index 119ae7eb1..649f05c69 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiInfo.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiInfo.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -51,7 +52,7 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -70,7 +71,7 @@ public OpenApiInfo(OpenApiInfo info) TermsOfService = info?.TermsOfService ?? TermsOfService; Contact = info?.Contact != null ? new(info.Contact) : null; License = info?.License != null ? new(info.License) : null; - Extensions = info?.Extensions != null ? new Dictionary(info.Extensions) : null; + Extensions = info?.Extensions != null ? new OpenApiExtensionDictionary(info.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs index c3c36812c..50bd22ba1 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLicense.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLicense.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -31,7 +32,7 @@ public class OpenApiLicense : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -46,7 +47,7 @@ public OpenApiLicense(OpenApiLicense license) Name = license?.Name ?? Name; Identifier = license?.Identifier ?? Identifier; Url = license?.Url != null ? new Uri(license.Url.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = license?.Extensions != null ? new Dictionary(license.Extensions) : null; + Extensions = license?.Extensions != null ? new OpenApiExtensionDictionary(license.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiLink.cs b/src/Microsoft.OpenApi/Models/OpenApiLink.cs index ea9202186..ed197394e 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiLink.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiLink.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -33,7 +34,7 @@ public class OpenApiLink : IOpenApiExtensible, IOpenApiLink public OpenApiServer? Server { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -52,7 +53,7 @@ internal OpenApiLink(IOpenApiLink link) RequestBody = link.RequestBody != null ? new(link.RequestBody) : null; Description = link.Description ?? Description; Server = link.Server != null ? new(link.Server) : null; - Extensions = link.Extensions != null ? new Dictionary(link.Extensions) : null; + Extensions = link.Extensions != null ? new OpenApiExtensionDictionary(link.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs index a16f8d11f..19e110051 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -45,7 +46,7 @@ public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible /// /// Serialize to Open Api v3.0. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -61,7 +62,7 @@ public OpenApiMediaType(OpenApiMediaType? mediaType) Example = mediaType?.Example != null ? JsonNodeCloneHelper.Clone(mediaType.Example) : null; Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples) : null; Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding) : null; - Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null; + Extensions = mediaType?.Extensions != null ? new OpenApiExtensionDictionary(mediaType.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs index 05c8da5e1..15728c37b 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlow.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -38,7 +39,7 @@ public class OpenApiOAuthFlow : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -54,7 +55,7 @@ public OpenApiOAuthFlow(OpenApiOAuthFlow oAuthFlow) TokenUrl = oAuthFlow?.TokenUrl != null ? new Uri(oAuthFlow.TokenUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; RefreshUrl = oAuthFlow?.RefreshUrl != null ? new Uri(oAuthFlow.RefreshUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; Scopes = oAuthFlow?.Scopes != null ? new Dictionary(oAuthFlow.Scopes) : null; - Extensions = oAuthFlow?.Extensions != null ? new Dictionary(oAuthFlow.Extensions) : null; + Extensions = oAuthFlow?.Extensions != null ? new OpenApiExtensionDictionary(oAuthFlow.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs index b46b41da1..8c29a3456 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOAuthFlows.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -36,7 +37,7 @@ public class OpenApiOAuthFlows : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -53,7 +54,7 @@ public OpenApiOAuthFlows(OpenApiOAuthFlows oAuthFlows) Password = oAuthFlows?.Password != null ? new(oAuthFlows.Password) : null; ClientCredentials = oAuthFlows?.ClientCredentials != null ? new(oAuthFlows.ClientCredentials) : null; AuthorizationCode = oAuthFlows?.AuthorizationCode != null ? new(oAuthFlows.AuthorizationCode) : null; - Extensions = oAuthFlows?.Extensions != null ? new Dictionary(oAuthFlows.Extensions) : null; + Extensions = oAuthFlows?.Extensions != null ? new OpenApiExtensionDictionary(oAuthFlows.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs index 3024f230a..706a17a48 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiOperation.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiOperation.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -123,7 +124,7 @@ public HashSet? Tags /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// public Dictionary? Metadata { get; set; } @@ -151,7 +152,7 @@ public OpenApiOperation(OpenApiOperation operation) Deprecated = operation.Deprecated; Security = operation.Security != null ? [.. operation.Security] : null; Servers = operation.Servers != null ? [.. operation.Servers] : null; - Extensions = operation.Extensions != null ? new Dictionary(operation.Extensions) : null; + Extensions = operation.Extensions != null ? new OpenApiExtensionDictionary(operation.Extensions) : null; Metadata = operation.Metadata != null ? new Dictionary(operation.Metadata) : null; } diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index a990ddcbb..bd36cdede 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Helpers; using Microsoft.OpenApi.Interfaces; @@ -70,7 +71,7 @@ public bool Explode public Dictionary? Content { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// A parameterless constructor @@ -94,7 +95,7 @@ internal OpenApiParameter(IOpenApiParameter parameter) Examples = parameter.Examples != null ? new Dictionary(parameter.Examples) : null; Example = parameter.Example != null ? JsonNodeCloneHelper.Clone(parameter.Example) : null; Content = parameter.Content != null ? new Dictionary(parameter.Content) : null; - Extensions = parameter.Extensions != null ? new Dictionary(parameter.Extensions) : null; + Extensions = parameter.Extensions != null ? new OpenApiExtensionDictionary(parameter.Extensions) : null; AllowEmptyValue = parameter.AllowEmptyValue; Deprecated = parameter.Deprecated; } @@ -269,7 +270,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // deprecated writer.WriteProperty(OpenApiConstants.Deprecated, Deprecated, false); - var extensionsClone = Extensions is not null ? new Dictionary(Extensions) : null; + var extensionsClone = Extensions is not null ? new OpenApiExtensionDictionary(Extensions) : null; // schema WriteRequestBodySchemaForV2(writer, extensionsClone); diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index a001b922c..88901889f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Net.Http; -using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -32,7 +32,7 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiPathItem public List? Parameters { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Add one operation into this path item. @@ -61,7 +61,7 @@ internal OpenApiPathItem(IOpenApiPathItem pathItem) Operations = pathItem.Operations != null ? new Dictionary(pathItem.Operations) : null; Servers = pathItem.Servers != null ? [.. pathItem.Servers] : null; Parameters = pathItem.Parameters != null ? [.. pathItem.Parameters] : null; - Extensions = pathItem.Extensions != null ? new Dictionary(pathItem.Extensions) : null; + Extensions = pathItem.Extensions != null ? new OpenApiExtensionDictionary(pathItem.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs index 302cfc5ae..cecfd1742 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs @@ -28,7 +28,7 @@ public class OpenApiRequestBody : IOpenApiExtensible, IOpenApiRequestBody public Dictionary? Content { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameter-less constructor @@ -44,7 +44,7 @@ internal OpenApiRequestBody(IOpenApiRequestBody requestBody) Description = requestBody.Description ?? Description; Required = requestBody.Required; Content = requestBody.Content != null ? new Dictionary(requestBody.Content) : null; - Extensions = requestBody.Extensions != null ? new Dictionary(requestBody.Extensions) : null; + Extensions = requestBody.Extensions != null ? new OpenApiExtensionDictionary(requestBody.Extensions) : null; } /// @@ -105,7 +105,7 @@ public IOpenApiParameter ConvertToBodyParameter(IOpenApiWriter writer) Schema = Content?.Values.FirstOrDefault()?.Schema ?? new OpenApiSchema(), Examples = Content?.Values.FirstOrDefault()?.Examples, Required = Required, - Extensions = Extensions?.ToDictionary(static k => k.Key, static v => v.Value) + Extensions = Extensions != null ? new OpenApiExtensionDictionary(Extensions) : null }; // Clone extensions so we can remove the x-bodyName extensions from the output V2 model. if (bodyParameter.Extensions is not null && diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs index 13ab81152..90214a5ec 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -28,7 +29,7 @@ public class OpenApiResponse : IOpenApiExtensible, IOpenApiResponse public Dictionary? Links { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -45,7 +46,7 @@ internal OpenApiResponse(IOpenApiResponse response) Headers = response.Headers != null ? new Dictionary(response.Headers) : null; Content = response.Content != null ? new Dictionary(response.Content) : null; Links = response.Links != null ? new Dictionary(response.Links) : null; - Extensions = response.Extensions != null ? new Dictionary(response.Extensions) : null; + Extensions = response.Extensions != null ? new OpenApiExtensionDictionary(response.Extensions) : null; } /// @@ -101,7 +102,7 @@ public void SerializeAsV2(IOpenApiWriter writer) // description writer.WriteRequiredProperty(OpenApiConstants.Description, Description); - var extensionsClone = Extensions is not null ? new Dictionary(Extensions) : null; + var extensionsClone = Extensions is not null ? new OpenApiExtensionDictionary(Extensions) : null; if (Content != null) { diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 94d0d9299..291aec55a 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.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; @@ -242,7 +242,7 @@ public string? Minimum public OpenApiXml? Xml { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// public Dictionary? UnrecognizedKeywords { get; set; } @@ -316,7 +316,7 @@ internal OpenApiSchema(IOpenApiSchema schema) 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; + Extensions = schema.Extensions != null ? new OpenApiExtensionDictionary(schema.Extensions) : null; Metadata = schema is IMetadataContainer { Metadata: not null } mContainer ? new Dictionary(mContainer.Metadata) : null; UnrecognizedKeywords = schema.UnrecognizedKeywords != null ? new Dictionary(schema.UnrecognizedKeywords) : null; DependentRequired = schema.DependentRequired != null ? new Dictionary>(schema.DependentRequired) : null; diff --git a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs index 992fe7986..a060109a0 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -40,7 +41,7 @@ public class OpenApiSecurityScheme : IOpenApiExtensible, IOpenApiSecurityScheme public Uri? OpenIdConnectUrl { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -61,7 +62,7 @@ internal OpenApiSecurityScheme(IOpenApiSecurityScheme securityScheme) BearerFormat = securityScheme.BearerFormat ?? BearerFormat; Flows = securityScheme.Flows != null ? new(securityScheme.Flows) : null; OpenIdConnectUrl = securityScheme.OpenIdConnectUrl != null ? new Uri(securityScheme.OpenIdConnectUrl.OriginalString, UriKind.RelativeOrAbsolute) : null; - Extensions = securityScheme.Extensions != null ? new Dictionary(securityScheme.Extensions) : null; + Extensions = securityScheme.Extensions != null ? new OpenApiExtensionDictionary(securityScheme.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServer.cs b/src/Microsoft.OpenApi/Models/OpenApiServer.cs index 9c5b3cfca..d313dbbd9 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServer.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServer.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -33,7 +34,7 @@ public class OpenApiServer : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -48,7 +49,7 @@ public OpenApiServer(OpenApiServer server) Description = server?.Description ?? Description; Url = server?.Url ?? Url; Variables = server?.Variables != null ? new Dictionary(server.Variables) : null; - Extensions = server?.Extensions != null ? new Dictionary(server.Extensions) : null; + Extensions = server?.Extensions != null ? new OpenApiExtensionDictionary(server.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs index 793c94d6c..60a8f5d45 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiServerVariable.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -34,7 +35,7 @@ public class OpenApiServerVariable : IOpenApiSerializable, IOpenApiExtensible /// /// This object MAY be extended with Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -49,7 +50,7 @@ public OpenApiServerVariable(OpenApiServerVariable serverVariable) Description = serverVariable?.Description; Default = serverVariable?.Default; Enum = serverVariable?.Enum != null ? new(serverVariable.Enum) : serverVariable?.Enum; - Extensions = serverVariable?.Extensions != null ? new Dictionary(serverVariable.Extensions) : serverVariable?.Extensions; + Extensions = serverVariable?.Extensions != null ? new OpenApiExtensionDictionary(serverVariable.Extensions) : serverVariable?.Extensions; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiTag.cs b/src/Microsoft.OpenApi/Models/OpenApiTag.cs index 253fab1de..e697f2d49 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiTag.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiTag.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -24,7 +25,7 @@ public class OpenApiTag : IOpenApiExtensible, IOpenApiTag, IOpenApiDescribedElem public OpenApiExternalDocs? ExternalDocs { get; set; } /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -40,7 +41,7 @@ internal OpenApiTag(IOpenApiTag tag) Name = tag.Name ?? Name; Description = tag.Description ?? Description; ExternalDocs = tag.ExternalDocs != null ? new(tag.ExternalDocs) : null; - Extensions = tag.Extensions != null ? new Dictionary(tag.Extensions) : null; + Extensions = tag.Extensions != null ? new OpenApiExtensionDictionary(tag.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/OpenApiXml.cs b/src/Microsoft.OpenApi/Models/OpenApiXml.cs index ae8a94a46..7d506fd44 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiXml.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiXml.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Writers; @@ -43,7 +44,7 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible /// /// Specification Extensions. /// - public Dictionary? Extensions { get; set; } + public OpenApiExtensionDictionary? Extensions { get; set; } /// /// Parameterless constructor @@ -60,7 +61,7 @@ public OpenApiXml(OpenApiXml xml) Prefix = xml?.Prefix ?? Prefix; Attribute = xml?.Attribute ?? Attribute; Wrapped = xml?.Wrapped ?? Wrapped; - Extensions = xml?.Extensions != null ? new Dictionary(xml.Extensions) : null; + Extensions = xml?.Extensions != null ? new OpenApiExtensionDictionary(xml.Extensions) : null; } /// diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index 1211561e4..921eb6f4a 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -41,7 +42,7 @@ private OpenApiCallbackReference(OpenApiCallbackReference callback):base(callbac public Dictionary? PathItems { get => Target?.PathItems; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 59cb7319e..9ea5efbe8 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -51,7 +52,7 @@ public string? Summary } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 fa8fe15eb..326b29f89 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -74,7 +75,7 @@ public string? Description public Dictionary? Content { get => Target?.Content; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 71f52ecd9..accba4ba1 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -58,7 +59,7 @@ public string? Description public RuntimeExpressionAnyWrapper? RequestBody { get => Target?.RequestBody; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 ae9322e41..5464ae797 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json.Nodes; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -79,7 +80,7 @@ public string? Description public Dictionary? Content { get => Target?.Content; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 a6ae2d405..9b938072c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Net.Http; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -62,7 +63,7 @@ public string? Description public List? Parameters { get => Target?.Parameters; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 f6bee476b..b97699bee 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -51,7 +52,7 @@ public string? Description public bool Required { get => Target?.Required ?? false; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 648b9c4c6..dd22ce457 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -52,7 +53,7 @@ public string? Description public Dictionary? Links { get => Target?.Links; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 6c191c8e5..f7253deee 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -134,7 +135,7 @@ public string? Description /// public OpenApiXml? Xml { get => Target?.Xml; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? Extensions { get => Target?.Extensions; } /// public Dictionary? UnrecognizedKeywords { get => Target?.UnrecognizedKeywords; } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index ff9c5b396..59ccf0407 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -57,7 +58,7 @@ public string? Description public Uri? OpenIdConnectUrl { get => Target?.OpenIdConnectUrl; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? 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 769764c9d..f622c9ff7 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -56,7 +57,7 @@ public string? Description public OpenApiExternalDocs? ExternalDocs { get => Target?.ExternalDocs; } /// - public Dictionary? Extensions { get => Target?.Extensions; } + public OpenApiExtensionDictionary? Extensions { get => Target?.Extensions; } /// public string? Name { get => Target?.Name; } diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs index 09ee79309..6d33193dd 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, Dictionary? extensions, OpenApiSpecVersion specVersion) + public static void WriteExtensions(this IOpenApiWriter writer, OpenApiExtensionDictionary? extensions, OpenApiSpecVersion specVersion) { Utils.CheckArgumentNull(writer); diff --git a/test/Microsoft.OpenApi.Readers.Tests/TestCustomExtension.cs b/test/Microsoft.OpenApi.Readers.Tests/TestCustomExtension.cs index c95378d5a..d764037bf 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/TestCustomExtension.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/TestCustomExtension.cs @@ -41,7 +41,8 @@ public void ParseCustomExtension() var diag = new OpenApiDiagnostic(); var actual = OpenApiDocument.Parse(description, "yaml", settings: settings); - var fooExtension = actual.Document.Info.Extensions["x-foo"] as FooExtension; + var extension = actual.Document.Info.Extensions["x-foo"] as IOpenApiExtension; + var fooExtension = extension as FooExtension; Assert.NotNull(fooExtension); Assert.Equal("hey", fooExtension.Bar); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs index 86ebfcab2..e8c6c7933 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.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.IO; @@ -38,7 +38,7 @@ public void ParseHeaderWithDefaultShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Default = new OpenApiAny(5).Node + Default = 5 } }, options => options @@ -67,12 +67,7 @@ public void ParseHeaderWithEnumShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Enum = - [ - new OpenApiAny(7).Node, - new OpenApiAny(8).Node, - new OpenApiAny(9).Node - ] + Enum = [ 7, 8, 9 ] } }, options => options.IgnoringCyclicReferences() .Excluding((IMemberInfo memberInfo) => diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs index 6e8685c4b..6554e157c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.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.IO; @@ -239,7 +239,7 @@ public void ParseParameterWithDefaultShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Default = new OpenApiAny(5).Node + Default = 5 } }, options => options.IgnoringCyclicReferences().Excluding(x => x.Schema.Default.Parent)); } @@ -266,12 +266,7 @@ public void ParseParameterWithEnumShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Enum = - [ - new OpenApiAny(7).Node, - new OpenApiAny(8).Node, - new OpenApiAny(9).Node - ] + Enum = [7, 8, 9] } }; diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs index 68f41271a..57bf0caac 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.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.IO; @@ -85,12 +85,7 @@ public void ParseSchemaWithEnumShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Enum = - [ - new OpenApiAny(7).Node, - new OpenApiAny(8).Node, - new OpenApiAny(9).Node - ] + Enum = [7, 8, 9] }; schema.Should().BeEquivalentTo(expected, options => diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs index fd7c5e478..cd70f3891 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs @@ -37,47 +37,47 @@ public async Task ParseAdvancedInfoShouldSucceed() Contact = new OpenApiContact { Email = "example@example.com", - Extensions = new Dictionary + Extensions = new OpenApiExtensionDictionary { - ["x-twitter"] = new OpenApiAny("@exampleTwitterHandler") + ["x-twitter"] = JsonValue.Create("@exampleTwitterHandler") }, Name = "John Doe", Url = new Uri("http://www.example.com/url1") }, License = new OpenApiLicense { - Extensions = new Dictionary + Extensions = new OpenApiExtensionDictionary { - ["x-disclaimer"] = new OpenApiAny("Sample Extension String Disclaimer") + ["x-disclaimer"] = JsonValue.Create("Sample Extension String Disclaimer") }, Name = "licenseName", Url = new Uri("http://www.example.com/url2") }, - Extensions = new Dictionary + Extensions = new OpenApiExtensionDictionary { - ["x-something"] = new OpenApiAny("Sample Extension String Something"), - ["x-contact"] = new OpenApiAny(new JsonObject() + ["x-something"] = JsonValue.Create("Sample Extension String Something"), + ["x-contact"] = new JsonObject() { ["name"] = "John Doe", ["url"] = "http://www.example.com/url3", ["email"] = "example@example.com" - }), - ["x-list"] = new OpenApiAny (new JsonArray { "1", "2" }) + }, + ["x-list"] = new JsonArray { "1", "2" } } }, options => options.IgnoringCyclicReferences() - .Excluding(i => ((OpenApiAny)i.Contact.Extensions["x-twitter"]).Node.Parent) - .Excluding(i => ((OpenApiAny)i.License.Extensions["x-disclaimer"]).Node.Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-something"]).Node.Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["name"].Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["name"].Root) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["url"].Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["url"].Root) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["email"].Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-contact"]).Node["email"].Root) - .Excluding(i => ((OpenApiAny)i.Extensions["x-list"]).Node[0].Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-list"]).Node[0].Root) - .Excluding(i => ((OpenApiAny)i.Extensions["x-list"]).Node[1].Parent) - .Excluding(i => ((OpenApiAny)i.Extensions["x-list"]).Node[1].Root)); + .Excluding(i => i.Contact.Extensions["x-twitter"].Node.Parent) + .Excluding(i => i.License.Extensions["x-disclaimer"].Node.Parent) + .Excluding(i => i.Extensions["x-something"].Node.Parent) + .Excluding(i => i.Extensions["x-contact"].Node["name"].Parent) + .Excluding(i => i.Extensions["x-contact"].Node["name"].Root) + .Excluding(i => i.Extensions["x-contact"].Node["url"].Parent) + .Excluding(i => i.Extensions["x-contact"].Node["url"].Root) + .Excluding(i => i.Extensions["x-contact"].Node["email"].Parent) + .Excluding(i => i.Extensions["x-contact"].Node["email"].Root) + .Excluding(i => i.Extensions["x-list"].Node[0].Parent) + .Excluding(i => i.Extensions["x-list"].Node[0].Root) + .Excluding(i => i.Extensions["x-list"].Node[1].Parent) + .Excluding(i => i.Extensions["x-list"].Node[1].Root)); } [Fact] diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index d9b4b1901..a91a41476 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -70,12 +70,12 @@ public void ParseExampleStringFragmentShouldSucceed() // Assert Assert.Equivalent(new OpenApiDiagnostic(), diagnostic); - openApiAny.Should().BeEquivalentTo(new OpenApiAny( + openApiAny.Should().BeEquivalentTo((OpenApiAny) new JsonObject { ["foo"] = "bar", ["baz"] = new JsonArray() { 1, 2 } - }), options => options.IgnoringCyclicReferences()); + }, options => options.IgnoringCyclicReferences()); } [Fact] @@ -213,8 +213,8 @@ public void ParseBasicSchemaWithExampleShouldSucceed() }, Example = new JsonObject { - ["name"] = new OpenApiAny("Puma").Node, - ["id"] = new OpenApiAny(1).Node + ["name"] = "Puma", + ["id"] = 1 } }, options => options .IgnoringCyclicReferences() diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs index a9bb4ba78..3df414698 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.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; @@ -74,11 +74,7 @@ public class OpenApiParameterTests Type = JsonSchemaType.Array, Items = new OpenApiSchema() { - Enum = - [ - new OpenApiAny("value1").Node, - new OpenApiAny("value2").Node - ] + Enum = ["value1", "value2"] } } }; @@ -95,11 +91,7 @@ public class OpenApiParameterTests Type = JsonSchemaType.Array, Items = new OpenApiSchema() { - Enum = - [ - new OpenApiAny("value1").Node, - new OpenApiAny("value2").Node - ] + Enum = ["value1", "value2"] } } }; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index 779a87e3e..575cec08c 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -473,7 +473,7 @@ public void OpenApiSchemaCopyConstructorSucceeds() } [Fact] - public void OpenApiSchemaCopyConstructorWithMetadataSucceeds() + public void OpenApiSchemaCopyConstructorWithMetadataAndExtensionsSucceeds() { var baseSchema = new OpenApiSchema { @@ -481,16 +481,23 @@ public void OpenApiSchemaCopyConstructorWithMetadataSucceeds() { ["key1"] = "value1", ["key2"] = 2 + }, + Extensions = new OpenApiExtensionDictionary + { + ["key1"] = JsonValue.Create("value1"), } }; var actualSchema = Assert.IsType(baseSchema.CreateShallowCopy()); Assert.Equal(baseSchema.Metadata["key1"], actualSchema.Metadata["key1"]); + Assert.Equal(baseSchema.Extensions["key1"], actualSchema.Extensions["key1"]); baseSchema.Metadata["key1"] = "value2"; + baseSchema.Extensions["key1"] = JsonValue.Create("value2"); Assert.NotEqual(baseSchema.Metadata["key1"], actualSchema.Metadata["key1"]); + Assert.NotEqual(baseSchema.Extensions["key1"], actualSchema.Extensions["key1"]); } public static TheoryData SchemaExamples() diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 1e3c88ec0..d1ede8258 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -10,6 +10,15 @@ namespace Microsoft.OpenApi.Any public OpenApiAny(System.Text.Json.Nodes.JsonNode jsonNode) { } public System.Text.Json.Nodes.JsonNode Node { get; } public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } + public static System.Text.Json.Nodes.JsonNode op_Implicit(Microsoft.OpenApi.Any.OpenApiAny openApiAny) { } + public static Microsoft.OpenApi.Any.OpenApiAny op_Implicit(System.Text.Json.Nodes.JsonNode jsonNode) { } + } + public class OpenApiExtensionDictionary : System.Collections.Generic.Dictionary + { + public OpenApiExtensionDictionary() { } + public OpenApiExtensionDictionary(Microsoft.OpenApi.Any.OpenApiExtensionDictionary extensions) { } + public Microsoft.OpenApi.Any.OpenApiAny this[string key] { get; set; } + public void Add(string key, object value) { } } } namespace Microsoft.OpenApi.Attributes @@ -205,7 +214,7 @@ namespace Microsoft.OpenApi.Interfaces public interface IOpenApiElement { } public interface IOpenApiExtensible : Microsoft.OpenApi.Interfaces.IOpenApiElement { - System.Collections.Generic.Dictionary? Extensions { get; set; } + Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } } public interface IOpenApiExtension { @@ -213,7 +222,7 @@ namespace Microsoft.OpenApi.Interfaces } public interface IOpenApiReadOnlyExtensible { - System.Collections.Generic.Dictionary? Extensions { get; } + Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } } public interface IOpenApiReader { @@ -491,7 +500,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.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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() { } @@ -505,7 +514,7 @@ namespace Microsoft.OpenApi.Models public OpenApiComponents(Microsoft.OpenApi.Models.OpenApiComponents? components) { } 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 Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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; } @@ -681,7 +690,7 @@ namespace Microsoft.OpenApi.Models public OpenApiContact() { } public OpenApiContact(Microsoft.OpenApi.Models.OpenApiContact contact) { } public string? Email { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? Name { get; set; } public System.Uri? Url { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -692,7 +701,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiDiscriminator() { } public OpenApiDiscriminator(Microsoft.OpenApi.Models.OpenApiDiscriminator discriminator) { } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public System.Collections.Generic.Dictionary? Mapping { get; set; } public string? PropertyName { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -705,7 +714,7 @@ 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.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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; } @@ -736,7 +745,7 @@ namespace Microsoft.OpenApi.Models public bool? AllowReserved { get; set; } public string? ContentType { get; set; } public bool? Explode { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -756,7 +765,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiExample() { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? ExternalValue { get; set; } public string? Summary { get; set; } public System.Text.Json.Nodes.JsonNode? Value { get; set; } @@ -769,8 +778,8 @@ namespace Microsoft.OpenApi.Models where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { protected OpenApiExtensibleDictionary() { } - protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary, System.Collections.Generic.Dictionary? extensions = null) { } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary dictionary, Microsoft.OpenApi.Any.OpenApiExtensionDictionary? extensions = null) { } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -780,7 +789,7 @@ namespace Microsoft.OpenApi.Models public OpenApiExternalDocs() { } public OpenApiExternalDocs(Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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,7 +806,7 @@ namespace Microsoft.OpenApi.Models public System.Text.Json.Nodes.JsonNode? Example { get; set; } public System.Collections.Generic.Dictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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; } @@ -812,7 +821,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.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiLicense? License { get; set; } public string? Summary { get; set; } public System.Uri? TermsOfService { get; set; } @@ -826,7 +835,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiLicense() { } public OpenApiLicense(Microsoft.OpenApi.Models.OpenApiLicense license) { } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? Identifier { get; set; } public string? Name { get; set; } public System.Uri? Url { get; set; } @@ -838,7 +847,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiLink() { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? OperationId { get; set; } public string? OperationRef { get; set; } public System.Collections.Generic.Dictionary? Parameters { get; set; } @@ -856,7 +865,7 @@ namespace Microsoft.OpenApi.Models public System.Collections.Generic.Dictionary? Encoding { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } public System.Collections.Generic.Dictionary? Examples { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -867,7 +876,7 @@ namespace Microsoft.OpenApi.Models public OpenApiOAuthFlow() { } public OpenApiOAuthFlow(Microsoft.OpenApi.Models.OpenApiOAuthFlow oAuthFlow) { } public System.Uri? AuthorizationUrl { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public System.Uri? RefreshUrl { get; set; } public System.Collections.Generic.Dictionary? Scopes { get; set; } public System.Uri? TokenUrl { get; set; } @@ -881,7 +890,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.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -896,7 +905,7 @@ namespace Microsoft.OpenApi.Models public System.Collections.Generic.Dictionary? Callbacks { get; set; } public bool Deprecated { get; set; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public System.Collections.Generic.Dictionary? Metadata { get; set; } public string? OperationId { get; set; } @@ -922,7 +931,7 @@ namespace Microsoft.OpenApi.Models public System.Text.Json.Nodes.JsonNode? Example { get; set; } public System.Collections.Generic.Dictionary? Examples { get; set; } public bool Explode { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } public string? Name { get; set; } public bool Required { get; set; } @@ -937,7 +946,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiPathItem() { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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; } @@ -977,7 +986,7 @@ namespace Microsoft.OpenApi.Models public OpenApiRequestBody() { } public System.Collections.Generic.Dictionary? Content { get; set; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -991,7 +1000,7 @@ namespace Microsoft.OpenApi.Models public OpenApiResponse() { } public System.Collections.Generic.Dictionary? Content { get; set; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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() { } @@ -1026,7 +1035,7 @@ namespace Microsoft.OpenApi.Models public System.Collections.Generic.List? Examples { get; set; } public string? ExclusiveMaximum { get; set; } public string? ExclusiveMinimum { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public string? Format { get; set; } public string? Id { get; set; } @@ -1074,7 +1083,7 @@ namespace Microsoft.OpenApi.Models public OpenApiSecurityScheme() { } public string? BearerFormat { get; set; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; set; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; set; } public string? Name { get; set; } @@ -1091,7 +1100,7 @@ namespace Microsoft.OpenApi.Models public OpenApiServer() { } public OpenApiServer(Microsoft.OpenApi.Models.OpenApiServer server) { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? Url { get; set; } public System.Collections.Generic.Dictionary? Variables { get; set; } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1105,7 +1114,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.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -1114,7 +1123,7 @@ namespace Microsoft.OpenApi.Models { public OpenApiTag() { } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public string? Name { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiTag CreateShallowCopy() { } @@ -1127,7 +1136,7 @@ namespace Microsoft.OpenApi.Models public OpenApiXml() { } public OpenApiXml(Microsoft.OpenApi.Models.OpenApiXml xml) { } public bool Attribute { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; set; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; set; } public string? Name { get; set; } public System.Uri? Namespace { get; set; } public string? Prefix { get; set; } @@ -1229,7 +1238,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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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() { } @@ -1239,7 +1248,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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public string? ExternalValue { get; } public string? Summary { get; set; } public System.Text.Json.Nodes.JsonNode? Value { get; } @@ -1258,7 +1267,7 @@ namespace Microsoft.OpenApi.Models.References public System.Text.Json.Nodes.JsonNode? Example { get; } public System.Collections.Generic.Dictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public bool Required { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Schema { get; } public Microsoft.OpenApi.Models.ParameterStyle? Style { get; } @@ -1269,7 +1278,7 @@ 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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public string? OperationId { get; } public string? OperationRef { get; } public System.Collections.Generic.Dictionary? Parameters { get; } @@ -1290,7 +1299,7 @@ namespace Microsoft.OpenApi.Models.References public System.Text.Json.Nodes.JsonNode? Example { get; } public System.Collections.Generic.Dictionary? Examples { get; } public bool Explode { get; } - public System.Collections.Generic.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } public string? Name { get; } public bool Required { get; } @@ -1303,7 +1312,7 @@ 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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public System.Collections.Generic.Dictionary? Operations { get; } public System.Collections.Generic.List? Parameters { get; } public System.Collections.Generic.List? Servers { get; } @@ -1317,7 +1326,7 @@ namespace Microsoft.OpenApi.Models.References public OpenApiRequestBodyReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public System.Collections.Generic.Dictionary? Content { get; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -1330,7 +1339,7 @@ namespace Microsoft.OpenApi.Models.References public OpenApiResponseReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument? hostDocument = null, string? externalResource = null) { } public System.Collections.Generic.Dictionary? Content { get; } public string? Description { get; set; } - public System.Collections.Generic.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? 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) { } @@ -1358,7 +1367,7 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.List? Examples { get; } public string? ExclusiveMaximum { get; } public string? ExclusiveMinimum { get; } - public System.Collections.Generic.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Format { get; } public string? Id { get; } @@ -1399,7 +1408,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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiOAuthFlows? Flows { get; } public Microsoft.OpenApi.Models.ParameterLocation? In { get; } public string? Name { get; } @@ -1413,7 +1422,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.Dictionary? Extensions { get; } + public Microsoft.OpenApi.Any.OpenApiExtensionDictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Name { get; } public override Microsoft.OpenApi.Models.Interfaces.IOpenApiTag? Target { get; } @@ -1914,7 +1923,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.Dictionary? extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } + public static void WriteExtensions(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.Any.OpenApiExtensionDictionary? extensions, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { } } public abstract class OpenApiWriterBase : Microsoft.OpenApi.Writers.IOpenApiWriter { diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index 1de888cd3..963fcf5c5 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs @@ -103,7 +103,7 @@ public void ValidateCustomExtension() { var ruleset = ValidationRuleSet.GetDefaultRuleSet(); - ruleset.Add(typeof(OpenApiAny), + ruleset.Add(typeof(OpenApiAny), new ValidationRule("FooExtensionRule", (context, item) => { @@ -131,9 +131,9 @@ public void ValidateCustomExtension() var extensionNode = JsonSerializer.Serialize(fooExtension); var jsonNode = JsonNode.Parse(extensionNode); - openApiDocument.Info.Extensions = new Dictionary + openApiDocument.Info.Extensions = new OpenApiExtensionDictionary { - { "x-foo", new OpenApiAny(jsonNode) } + { "x-foo", jsonNode } }; var validator = new OpenApiValidator(ruleset); @@ -150,8 +150,8 @@ public void ValidateCustomExtension() [Fact] public void RemoveRuleByName_Invalid() { - Assert.Throws(() => new ValidationRule(null, (vc, oaa) => { })); - Assert.Throws(() => new ValidationRule(string.Empty, (vc, oaa) => { })); + Assert.Throws(() => new ValidationRule(null, (vc, oaa) => { })); + Assert.Throws(() => new ValidationRule(string.Empty, (vc, oaa) => { })); } [Fact] diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs index f0c772473..402758a29 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.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; @@ -75,19 +75,19 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema() { Enum = [ - new OpenApiAny("1").Node, - new OpenApiAny(new JsonObject() + 1, + new JsonObject() { ["x"] = 2, ["y"] = "20", ["z"] = "200" - }).Node, - new OpenApiAny(new JsonArray() { 3 }).Node, - new OpenApiAny(new JsonObject() + }, + new JsonArray() { 3 }, + new JsonObject() { ["x"] = 4, ["y"] = 40, - }).Node + } ], Type = JsonSchemaType.Object, AdditionalProperties = new OpenApiSchema() diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs index 9824b17f6..f344150ee 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiTagValidationTests.cs @@ -42,9 +42,9 @@ public void ValidateExtensionNameStartsWithXDashInTag() { Name = "tag" }; - tag.Extensions = new Dictionary + tag.Extensions = new OpenApiExtensionDictionary { - { "tagExt", new OpenApiAny("value") } + { "tagExt", "value" } }; // Act diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index fb149b5ec..ff4c5bb7a 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs @@ -10,10 +10,8 @@ using System.Text; using System.Text.Encodings.Web; using System.Text.Json; -using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Threading.Tasks; -using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Writers; using Xunit; @@ -318,12 +316,7 @@ public void OpenApiJsonWriterOutputsValidJsonValueWhenSchemaHasNanOrInfinityValu // Arrange var schema = new OpenApiSchema { - Enum = - [ - new OpenApiAny("NaN").Node, - new OpenApiAny("Infinity").Node, - new OpenApiAny("-Infinity").Node - ] + Enum = ["NaN", "Infinity", "-Infinity"] }; // Act @@ -333,7 +326,7 @@ public void OpenApiJsonWriterOutputsValidJsonValueWhenSchemaHasNanOrInfinityValu var jsonString = schemaBuilder.ToString(); // Assert - var exception = Record.Exception(() => System.Text.Json.JsonSerializer.Deserialize>(jsonString)); + var exception = Record.Exception(() => JsonSerializer.Deserialize>(jsonString)); Assert.Null(exception); } }