From eb5a8db60606904436e316d87c4f05059c3f6f93 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Wed, 19 Mar 2025 13:52:56 +0300 Subject: [PATCH 01/10] fix: add implicit conversion from JsonNode to OpenApiAny and vice versa --- src/Microsoft.OpenApi/Any/OpenApiAny.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; } } From d2f54aed6c65a3e4a335fffda032a6c1baf0dbb1 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 14:19:33 +0300 Subject: [PATCH 02/10] chore: update examples, defaults and enum values --- .../Any/ExtensionDictionary.cs | 127 ++++++++++++++++++ .../V2Tests/OpenApiHeaderTests.cs | 9 +- .../V2Tests/OpenApiParameterTests.cs | 9 +- .../V2Tests/OpenApiSchemaTests.cs | 7 +- .../V3Tests/OpenApiSchemaTests.cs | 4 +- .../Models/OpenApiParameterTests.cs | 12 +- .../Services/OpenApiValidatorTests.cs | 6 +- .../OpenApiSchemaValidationTests.cs | 18 +-- .../Writers/OpenApiJsonWriterTests.cs | 7 +- 9 files changed, 149 insertions(+), 50 deletions(-) create mode 100644 src/Microsoft.OpenApi/Any/ExtensionDictionary.cs diff --git a/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs b/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs new file mode 100644 index 000000000..6fb451e8d --- /dev/null +++ b/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Nodes; +using Microsoft.OpenApi.Interfaces; + +namespace Microsoft.OpenApi.Any +{ + /// + /// + /// + public class ExtensionDictionary : IDictionary + { + private readonly Dictionary _inner = new(); + + /// + /// Allow simplified usage via object indexer + /// + /// + /// + public IOpenApiExtension this[string key] + { + get => _inner[key]; + set => _inner[key] = ConvertToExtension(value); + } + + /// + /// Allow setting JsonNode directly + /// + /// + /// + public void Set(string key, JsonNode node) + { + _inner[key] = new OpenApiAny(node); + } + + /// + /// Allow simplified usage via object indexer + /// + /// + /// + /// + public object this[string key, JsonNode node] + { + set => Set(key, node); + } + + private static IOpenApiExtension ConvertToExtension(IOpenApiExtension extension) + { + // Just in case you want to extend in future to convert primitives + return extension; + } + + /// + /// Core IDictionary implementation + /// + /// + /// + public void Add(string key, IOpenApiExtension value) => _inner.Add(key, ConvertToExtension(value)); + + /// + /// Checks whether a key exists in the dictionary. + /// + /// + /// + public bool ContainsKey(string key) => _inner.ContainsKey(key); + + /// + /// Remove the extension value for the given key. + /// + /// + /// + public bool Remove(string key) => _inner.Remove(key); + /// + /// Get the extension value for the given key. + /// + /// + /// + /// + public bool TryGetValue(string key, out IOpenApiExtension value) => _inner.TryGetValue(key, out value); + + /// + /// Get the keys in the dictionary. + /// + public ICollection Keys => _inner.Keys; + + /// + /// Get the values in the dictionary. + /// + public ICollection Values => _inner.Values; + + /// + /// Get the number of items in the dictionary. + /// + public int Count => _inner.Count; + + /// + /// Checks if the dictionary is read-only. + /// + public bool IsReadOnly => false; + + /// + /// Add an item to the dictionary. + /// + /// + public void Add(KeyValuePair item) => Add(item.Key, item.Value); + + /// + /// Clears the dictionary. + /// + public void Clear() => _inner.Clear(); + + /// + /// Checks if the dictionary contains a key-value pair. + /// + /// + /// + public bool Contains(KeyValuePair item) => _inner.Contains(item); + public void CopyTo(KeyValuePair[] array, int arrayIndex) => + ((IDictionary)_inner).CopyTo(array, arrayIndex); + public bool Remove(KeyValuePair item) => _inner.Remove(item.Key); + public IEnumerator> GetEnumerator() => _inner.GetEnumerator(); + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _inner.GetEnumerator(); + } + +} diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs index 1b1187a42..d8327ace2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs @@ -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 aa11d5137..9d2ed9746 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs @@ -237,7 +237,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)); } @@ -264,12 +264,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 781b272e1..a581ebac8 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs @@ -85,12 +85,7 @@ public void ParseSchemaWithEnumShouldSucceed() { Type = JsonSchemaType.Number, Format = "float", - Enum = new List - { - 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/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index cdc80e603..b37fb9c20 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -212,8 +212,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 da0c00d44..189410ec6 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs @@ -73,11 +73,7 @@ public class OpenApiParameterTests Type = JsonSchemaType.Array, Items = new OpenApiSchema() { - Enum = - { - new OpenApiAny("value1").Node, - new OpenApiAny("value2").Node - } + Enum = ["value1", "value2"] } } }; @@ -94,11 +90,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/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index 90f88e378..7b33a8060 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) => { @@ -147,8 +147,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 d8820defc..1a783e596 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiSchemaValidationTests.cs @@ -73,22 +73,22 @@ public void ValidateEnumShouldNotHaveDataTypeMismatchForSimpleSchema() IEnumerable warnings; var schema = new OpenApiSchema() { - Enum = - { - new OpenApiAny("1").Node, - new OpenApiAny(new JsonObject() + Enum = + [ + 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/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index 54fb8cfb6..9267bb574 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs @@ -325,12 +325,7 @@ public void OpenApiJsonWriterOutputsValidJsonValueWhenSchemaHasNanOrInfinityValu // Arrange var schema = new OpenApiSchema { - Enum = new List - { - new OpenApiAny("NaN").Node, - new OpenApiAny("Infinity").Node, - new OpenApiAny("-Infinity").Node - } + Enum = ["NaN", "Infinity", "-Infinity"] }; // Act From 2a45f4a29be38fe7710d12c80082b4f692c4b3f4 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 14:29:42 +0300 Subject: [PATCH 03/10] chore: remove file --- .../Any/ExtensionDictionary.cs | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 src/Microsoft.OpenApi/Any/ExtensionDictionary.cs diff --git a/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs b/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs deleted file mode 100644 index 6fb451e8d..000000000 --- a/src/Microsoft.OpenApi/Any/ExtensionDictionary.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Nodes; -using Microsoft.OpenApi.Interfaces; - -namespace Microsoft.OpenApi.Any -{ - /// - /// - /// - public class ExtensionDictionary : IDictionary - { - private readonly Dictionary _inner = new(); - - /// - /// Allow simplified usage via object indexer - /// - /// - /// - public IOpenApiExtension this[string key] - { - get => _inner[key]; - set => _inner[key] = ConvertToExtension(value); - } - - /// - /// Allow setting JsonNode directly - /// - /// - /// - public void Set(string key, JsonNode node) - { - _inner[key] = new OpenApiAny(node); - } - - /// - /// Allow simplified usage via object indexer - /// - /// - /// - /// - public object this[string key, JsonNode node] - { - set => Set(key, node); - } - - private static IOpenApiExtension ConvertToExtension(IOpenApiExtension extension) - { - // Just in case you want to extend in future to convert primitives - return extension; - } - - /// - /// Core IDictionary implementation - /// - /// - /// - public void Add(string key, IOpenApiExtension value) => _inner.Add(key, ConvertToExtension(value)); - - /// - /// Checks whether a key exists in the dictionary. - /// - /// - /// - public bool ContainsKey(string key) => _inner.ContainsKey(key); - - /// - /// Remove the extension value for the given key. - /// - /// - /// - public bool Remove(string key) => _inner.Remove(key); - /// - /// Get the extension value for the given key. - /// - /// - /// - /// - public bool TryGetValue(string key, out IOpenApiExtension value) => _inner.TryGetValue(key, out value); - - /// - /// Get the keys in the dictionary. - /// - public ICollection Keys => _inner.Keys; - - /// - /// Get the values in the dictionary. - /// - public ICollection Values => _inner.Values; - - /// - /// Get the number of items in the dictionary. - /// - public int Count => _inner.Count; - - /// - /// Checks if the dictionary is read-only. - /// - public bool IsReadOnly => false; - - /// - /// Add an item to the dictionary. - /// - /// - public void Add(KeyValuePair item) => Add(item.Key, item.Value); - - /// - /// Clears the dictionary. - /// - public void Clear() => _inner.Clear(); - - /// - /// Checks if the dictionary contains a key-value pair. - /// - /// - /// - public bool Contains(KeyValuePair item) => _inner.Contains(item); - public void CopyTo(KeyValuePair[] array, int arrayIndex) => - ((IDictionary)_inner).CopyTo(array, arrayIndex); - public bool Remove(KeyValuePair item) => _inner.Remove(item.Key); - public IEnumerator> GetEnumerator() => _inner.GetEnumerator(); - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => _inner.GetEnumerator(); - } - -} From 5384afafe60a5088e4016ec8f5b315ae7f1c63f5 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 15 Apr 2025 10:14:54 +0300 Subject: [PATCH 04/10] chore: add namespace reference --- .../Writers/OpenApiJsonWriterTests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs index e29d2b2f7..ff4c5bb7a 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiJsonWriterTests.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; @@ -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; @@ -328,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); } } From 9022ba63a8636da1e1eedc49bc1592d3f86be658 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 15 Apr 2025 11:03:30 +0300 Subject: [PATCH 05/10] fix: override base class indexer to set OpenApiAny values --- .../Any/OpenApiExtensionDictionary.cs | 65 +++++++++++++++++++ .../Interfaces/IOpenApiExtensible.cs | 3 +- .../Models/OpenApiCallback.cs | 5 +- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs diff --git a/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs new file mode 100644 index 000000000..222712719 --- /dev/null +++ b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs @@ -0,0 +1,65 @@ +// 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 + { + /// + /// 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, + _ => throw new InvalidOperationException($"Cannot convert value of type '{value?.GetType().Name}' to IOpenApiExtension.") + }; + } + + /// + /// Test the OpenApiExtensionDictionary and base class implementations. + /// + public static void TestExtensions() + { + var jsonNode = new JsonObject(); + var extensions = new OpenApiExtensionDictionary + { + ["x-key"] = jsonNode + }; + extensions.Add("x-key", jsonNode); + var extensions2 = new Dictionary + { + ["x-key"] = (OpenApiAny)jsonNode + }; + extensions2.Add("x-key", (OpenApiAny)jsonNode); + } + } +} 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/Models/OpenApiCallback.cs b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs index 8bd90ed7f..1f18d3bb1 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 @@ -90,6 +92,7 @@ internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion versio // extensions writer.WriteExtensions(Extensions, version); + Extensions!["x-extensions"] = new JsonObject(); //this works writer.WriteEndObject(); } From 7f9d8401dccb321df01ed81f72ccb5c2cbaf3a1e Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 17 Apr 2025 18:35:12 +0300 Subject: [PATCH 06/10] chore: add constructors and clean up --- .../Any/OpenApiExtensionDictionary.cs | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs index 222712719..236e3c07e 100644 --- a/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs +++ b/src/Microsoft.OpenApi/Any/OpenApiExtensionDictionary.cs @@ -13,6 +13,17 @@ namespace Microsoft.OpenApi.Any /// 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. /// @@ -21,7 +32,7 @@ public class OpenApiExtensionDictionary : Dictionary public new OpenApiAny this[string key] { get => (OpenApiAny)base[key]; - set => base[key] = ConvertIfJsonNode(value); + set => base[key] = ConvertIfJsonNode(value)!; } /// @@ -31,35 +42,17 @@ public class OpenApiExtensionDictionary : Dictionary /// public void Add(string key, object value) { - base.Add(key, ConvertIfJsonNode(value)); + base.Add(key, ConvertIfJsonNode(value)!); } - private static IOpenApiExtension ConvertIfJsonNode(object? value) + private static IOpenApiExtension? ConvertIfJsonNode(object? value) { return value switch { IOpenApiExtension extension => extension, JsonNode node => (OpenApiAny)node, - _ => throw new InvalidOperationException($"Cannot convert value of type '{value?.GetType().Name}' to IOpenApiExtension.") - }; - } - - /// - /// Test the OpenApiExtensionDictionary and base class implementations. - /// - public static void TestExtensions() - { - var jsonNode = new JsonObject(); - var extensions = new OpenApiExtensionDictionary - { - ["x-key"] = jsonNode - }; - extensions.Add("x-key", jsonNode); - var extensions2 = new Dictionary - { - ["x-key"] = (OpenApiAny)jsonNode + _ => null }; - extensions2.Add("x-key", (OpenApiAny)jsonNode); } } } From 404ba4ff1b6a636e969d75b4ca914c14a7183657 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 17 Apr 2025 18:45:12 +0300 Subject: [PATCH 07/10] chore: refactor to update Extensions type to OpenApiExtensionDictionary --- .../Extensions/OpenApiExtensibleExtensions.cs | 5 +-- .../Interfaces/IOpenApiReadOnlyExtensible.cs | 8 ++-- .../Models/OpenApiCallback.cs | 3 +- .../Models/OpenApiComponents.cs | 5 ++- .../Models/OpenApiContact.cs | 5 ++- .../Models/OpenApiDiscriminator.cs | 5 ++- .../Models/OpenApiDocument.cs | 5 ++- .../Models/OpenApiEncoding.cs | 5 ++- .../Models/OpenApiExample.cs | 5 ++- .../Models/OpenApiExtensibleDictionary.cs | 7 +-- .../Models/OpenApiExternalDocs.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiInfo.cs | 5 ++- .../Models/OpenApiLicense.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiLink.cs | 5 ++- .../Models/OpenApiMediaType.cs | 5 ++- .../Models/OpenApiOAuthFlow.cs | 5 ++- .../Models/OpenApiOAuthFlows.cs | 5 ++- .../Models/OpenApiOperation.cs | 5 ++- .../Models/OpenApiParameter.cs | 7 +-- .../Models/OpenApiPathItem.cs | 6 +-- .../Models/OpenApiRequestBody.cs | 6 +-- .../Models/OpenApiResponse.cs | 7 +-- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 4 +- .../Models/OpenApiSecurityScheme.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiServer.cs | 5 ++- .../Models/OpenApiServerVariable.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiTag.cs | 5 ++- src/Microsoft.OpenApi/Models/OpenApiXml.cs | 5 ++- .../References/OpenApiCallbackReference.cs | 3 +- .../References/OpenApiExampleReference.cs | 3 +- .../References/OpenApiHeaderReference.cs | 3 +- .../Models/References/OpenApiLinkReference.cs | 3 +- .../References/OpenApiParameterReference.cs | 3 +- .../References/OpenApiPathItemReference.cs | 3 +- .../References/OpenApiRequestBodyReference.cs | 3 +- .../References/OpenApiResponseReference.cs | 3 +- .../References/OpenApiSchemaReference.cs | 3 +- .../OpenApiSecuritySchemeReference.cs | 3 +- .../Models/References/OpenApiTagReference.cs | 3 +- .../Writers/OpenApiWriterAnyExtensions.cs | 2 +- .../TestCustomExtension.cs | 3 +- .../V3Tests/OpenApiInfoTests.cs | 44 +++++++++---------- .../Models/OpenApiSchemaTests.cs | 9 +++- .../Services/OpenApiValidatorTests.cs | 4 +- .../Validations/OpenApiTagValidationTests.cs | 4 +- 46 files changed, 147 insertions(+), 105 deletions(-) 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/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 1f18d3bb1..caa6599ac 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiCallback.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiCallback.cs @@ -38,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; } /// @@ -92,7 +92,6 @@ internal void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion versio // extensions writer.WriteExtensions(Extensions, version); - Extensions!["x-extensions"] = new JsonObject(); //this works writer.WriteEndObject(); } 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 0f15a27d9..72bdd8ce4 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 592d9cb58..8ad388960 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.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; @@ -122,7 +123,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; } @@ -150,7 +151,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 fd74c2b57..c65377d3f 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; } @@ -199,7 +200,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 if (this is OpenApiBodyParameter) 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 28c3e30c9..15644651f 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -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; 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; 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 7dd3ea3e5..b4fe92ee9 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 cd3af84ba..599548620 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.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; @@ -57,7 +58,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 222d7a24e..dd2b26d06 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/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.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index 6e2f00656..08718a5e1 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 OpenApiSchemaCopyConstructorWithAnnotationsSucceeds() + public void OpenApiSchemaCopyConstructorWithAnnotationsAndExtensionsSucceeds() { var baseSchema = new OpenApiSchema { @@ -481,16 +481,23 @@ public void OpenApiSchemaCopyConstructorWithAnnotationsSucceeds() { ["key1"] = "value1", ["key2"] = 2 + }, + Extensions = new OpenApiExtensionDictionary + { + ["key1"] = JsonValue.Create("value1"), } }; var actualSchema = baseSchema.CreateShallowCopy(); Assert.Equal(baseSchema.Annotations["key1"], actualSchema.Annotations["key1"]); + Assert.Equal(baseSchema.Extensions["key1"], actualSchema.Extensions["key1"]); baseSchema.Annotations["key1"] = "value2"; + baseSchema.Extensions["key1"] = JsonValue.Create("value2"); Assert.NotEqual(baseSchema.Annotations["key1"], actualSchema.Annotations["key1"]); + Assert.NotEqual(baseSchema.Extensions["key1"], actualSchema.Extensions["key1"]); } public static TheoryData SchemaExamples() diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index 714e98153..963fcf5c5 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs @@ -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); 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 From f7e637f0d1bbd77e695b4aa4cb58dbbb081df4a6 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 17 Apr 2025 18:45:33 +0300 Subject: [PATCH 08/10] chore: use implicit operator --- .../V3Tests/OpenApiSchemaTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index d552a412c..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] From 4babf077e261c696b583c25f10e6cfd2c42eee16 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 17 Apr 2025 18:48:07 +0300 Subject: [PATCH 09/10] chore: update public API --- .../PublicApi/PublicApi.approved.txt | 93 ++++++++++--------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 4a8fcea74..27dd89caf 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 { @@ -497,7 +506,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() { } @@ -511,7 +520,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; } @@ -687,7 +696,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) { } @@ -698,7 +707,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) { } @@ -711,7 +720,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; } @@ -742,7 +751,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) { } @@ -762,7 +771,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; } @@ -775,8 +784,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) { } @@ -786,7 +795,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) { } @@ -803,7 +812,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; } @@ -818,7 +827,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; } @@ -832,7 +841,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; } @@ -844,7 +853,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; } @@ -862,7 +871,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) { } @@ -873,7 +882,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; } @@ -887,7 +896,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) { } @@ -902,7 +911,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; } @@ -928,7 +937,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; } @@ -943,7 +952,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; } @@ -983,7 +992,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) { } @@ -997,7 +1006,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() { } @@ -1033,7 +1042,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; } @@ -1080,7 +1089,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; } @@ -1097,7 +1106,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) { } @@ -1111,7 +1120,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) { } @@ -1120,7 +1129,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() { } @@ -1133,7 +1142,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; } @@ -1235,7 +1244,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() { } @@ -1245,7 +1254,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; } @@ -1264,7 +1273,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; } @@ -1275,7 +1284,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; } @@ -1296,7 +1305,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; } @@ -1309,7 +1318,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; } @@ -1323,7 +1332,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) { } @@ -1336,7 +1345,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) { } @@ -1365,7 +1374,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; } @@ -1406,7 +1415,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; } @@ -1420,7 +1429,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; } @@ -1921,7 +1930,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 { From f8341bb4b96b80799f5ddc217dadec3f8ec7cc3e Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Thu, 17 Apr 2025 19:05:41 +0300 Subject: [PATCH 10/10] chore: clean up --- src/Microsoft.OpenApi/Models/OpenApiParameter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs index cf9867671..bd36cdede 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.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; @@ -270,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);