From 161605f1d765290506cc411d061287b95686cced Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Oct 2025 18:26:30 +0000
Subject: [PATCH 01/20] Initial plan
From 31b38210e819ccc7b9422d591afecc53ef70d161 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Oct 2025 18:40:18 +0000
Subject: [PATCH 02/20] Add support for media types components in OAS 3.2.0
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
---
.../Models/Interfaces/IOpenApiMediaType.cs | 57 ++++++++++++++
.../Models/OpenApiComponents.cs | 29 +++++++
.../Models/OpenApiConstants.cs | 5 ++
.../Models/OpenApiMediaType.cs | 25 +++++-
src/Microsoft.OpenApi/Models/ReferenceType.cs | 7 +-
.../References/OpenApiMediaTypeReference.cs | 78 +++++++++++++++++++
.../Services/OpenApiWalker.cs | 23 ++++++
.../Services/OpenApiWorkspace.cs | 11 +++
.../PublicApi/PublicApi.approved.txt | 32 +++++++-
9 files changed, 264 insertions(+), 3 deletions(-)
create mode 100644 src/Microsoft.OpenApi/Models/Interfaces/IOpenApiMediaType.cs
create mode 100644 src/Microsoft.OpenApi/Models/References/OpenApiMediaTypeReference.cs
diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiMediaType.cs
new file mode 100644
index 000000000..154430d51
--- /dev/null
+++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiMediaType.cs
@@ -0,0 +1,57 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+using System.Collections.Generic;
+using System.Text.Json.Nodes;
+
+namespace Microsoft.OpenApi;
+
+///
+/// Defines the base properties for the media type object.
+/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
+///
+public interface IOpenApiMediaType : IOpenApiReadOnlyExtensible, IShallowCopyable, IOpenApiReferenceable
+{
+ ///
+ /// The schema defining the type used for the request body.
+ ///
+ public IOpenApiSchema? Schema { get; }
+
+ ///
+ /// The schema defining the type used for the items in an array media type.
+ /// This property is only applicable for OAS 3.2.0 and later.
+ ///
+ public IOpenApiSchema? ItemSchema { get; }
+
+ ///
+ /// Example of the media type.
+ /// The example object SHOULD be in the correct format as specified by the media type.
+ ///
+ public JsonNode? Example { get; }
+
+ ///
+ /// Examples of the media type.
+ /// Each example object SHOULD match the media type and specified schema if present.
+ ///
+ public IDictionary? Examples { get; }
+
+ ///
+ /// A map between a property name and its encoding information.
+ /// The key, being the property name, MUST exist in the schema as a property.
+ /// The encoding object SHALL only apply to requestBody objects
+ /// when the media type is multipart or application/x-www-form-urlencoded.
+ ///
+ public IDictionary? Encoding { get; }
+
+ ///
+ /// An encoding object for items in an array schema.
+ /// Only applies when the schema is of type array.
+ ///
+ public OpenApiEncoding? ItemEncoding { get; }
+
+ ///
+ /// An array of encoding objects for prefixItems in an array schema.
+ /// Each element corresponds to a prefixItem in the schema.
+ ///
+ public IList? PrefixEncoding { get; }
+}
diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
index 9f544f1bd..1b9b0830d 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
@@ -62,6 +62,11 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
///
public IDictionary? PathItems { get; set; }
+ ///
+ /// An object to hold reusable Objects.
+ ///
+ public IDictionary? MediaTypes { get; set; }
+
///
/// This object MAY be extended with Specification Extensions.
///
@@ -87,6 +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;
+ MediaTypes = components?.MediaTypes != null ? new Dictionary(components.MediaTypes) : null;
Extensions = components?.Extensions != null ? new Dictionary(components.Extensions) : null;
}
@@ -314,6 +320,29 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
}
});
+ // mediaTypes - serialize as native field in v3.2+, as extension in earlier versions
+ if (MediaTypes != null)
+ {
+ var mediaTypesFieldName = version >= OpenApiSpecVersion.OpenApi3_2
+ ? OpenApiConstants.MediaTypes
+ : OpenApiConstants.ExtensionFieldNamePrefix + "oai-" + OpenApiConstants.MediaTypes;
+
+ writer.WriteOptionalMap(
+ mediaTypesFieldName,
+ MediaTypes,
+ (w, key, component) =>
+ {
+ if (component is OpenApiMediaTypeReference reference)
+ {
+ action(w, reference);
+ }
+ else
+ {
+ callback(w, component);
+ }
+ });
+ }
+
// extensions
writer.WriteExtensions(Extensions, version);
writer.WriteEndObject();
diff --git a/src/Microsoft.OpenApi/Models/OpenApiConstants.cs b/src/Microsoft.OpenApi/Models/OpenApiConstants.cs
index 1756f9dde..a40d1f1cb 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiConstants.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiConstants.cs
@@ -395,6 +395,11 @@ public static class OpenApiConstants
///
public const string Callbacks = "callbacks";
+ ///
+ /// Field: MediaTypes
+ ///
+ public const string MediaTypes = "mediaTypes";
+
///
/// Field: Url
///
diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
index f8e9acab9..c9ceb9284 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
@@ -11,7 +11,7 @@ namespace Microsoft.OpenApi
///
/// Media Type Object.
///
- public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible
+ public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible, IOpenApiMediaType
{
///
/// The schema defining the type used for the request body.
@@ -81,6 +81,29 @@ public OpenApiMediaType(OpenApiMediaType? mediaType)
Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null;
}
+ ///
+ /// Initializes a copy of an object
+ ///
+ internal OpenApiMediaType(IOpenApiMediaType mediaType)
+ {
+ Schema = mediaType?.Schema?.CreateShallowCopy();
+ ItemSchema = mediaType?.ItemSchema?.CreateShallowCopy();
+ 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;
+ ItemEncoding = mediaType?.ItemEncoding != null ? new OpenApiEncoding(mediaType.ItemEncoding) : null;
+ PrefixEncoding = mediaType?.PrefixEncoding != null ? new List(mediaType.PrefixEncoding.Select(e => new OpenApiEncoding(e))) : null;
+ Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null;
+ }
+
+ ///
+ /// Creates a shallow copy of this object
+ ///
+ public IOpenApiMediaType CreateShallowCopy()
+ {
+ return new OpenApiMediaType(this);
+ }
+
///
/// Serialize to Open Api v3.2.
///
diff --git a/src/Microsoft.OpenApi/Models/ReferenceType.cs b/src/Microsoft.OpenApi/Models/ReferenceType.cs
index b33a22e51..cfad69089 100644
--- a/src/Microsoft.OpenApi/Models/ReferenceType.cs
+++ b/src/Microsoft.OpenApi/Models/ReferenceType.cs
@@ -61,6 +61,11 @@ public enum ReferenceType
///
/// Path item.
///
- [Display("pathItems")] PathItem
+ [Display("pathItems")] PathItem,
+
+ ///
+ /// MediaTypes item.
+ ///
+ [Display("mediaTypes")] MediaType
}
}
diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiMediaTypeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiMediaTypeReference.cs
new file mode 100644
index 000000000..2f5732eff
--- /dev/null
+++ b/src/Microsoft.OpenApi/Models/References/OpenApiMediaTypeReference.cs
@@ -0,0 +1,78 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+using System.Collections.Generic;
+using System.Text.Json.Nodes;
+
+namespace Microsoft.OpenApi
+{
+ ///
+ /// Media Type Object Reference.
+ ///
+ public class OpenApiMediaTypeReference : BaseOpenApiReferenceHolder, IOpenApiMediaType
+ {
+ ///
+ /// Constructor initializing the reference object.
+ ///
+ /// The reference Id.
+ /// The host OpenAPI document.
+ /// Optional: External resource in the reference.
+ /// It may be:
+ /// 1. a absolute/relative file path, for example: ../commons/pet.json
+ /// 2. a Url, for example: http://localhost/pet.json
+ ///
+ public OpenApiMediaTypeReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null) : base(referenceId, hostDocument, ReferenceType.MediaType, externalResource)
+ {
+ }
+
+ ///
+ /// Copy constructor
+ ///
+ /// The media type reference to copy
+ private OpenApiMediaTypeReference(OpenApiMediaTypeReference mediaTypeReference) : base(mediaTypeReference)
+ {
+ }
+
+ ///
+ public IOpenApiSchema? Schema { get => Target?.Schema; }
+
+ ///
+ public IOpenApiSchema? ItemSchema { get => Target?.ItemSchema; }
+
+ ///
+ public JsonNode? Example { get => Target?.Example; }
+
+ ///
+ public IDictionary? Examples { get => Target?.Examples; }
+
+ ///
+ public IDictionary? Encoding { get => Target?.Encoding; }
+
+ ///
+ public OpenApiEncoding? ItemEncoding { get => Target?.ItemEncoding; }
+
+ ///
+ public IList? PrefixEncoding { get => Target?.PrefixEncoding; }
+
+ ///
+ public IDictionary? Extensions { get => Target?.Extensions; }
+
+ ///
+ public override IOpenApiMediaType CopyReferenceAsTargetElementWithOverrides(IOpenApiMediaType source)
+ {
+ return source is OpenApiMediaType ? new OpenApiMediaType(this) : source;
+ }
+
+ ///
+ public IOpenApiMediaType CreateShallowCopy()
+ {
+ return new OpenApiMediaTypeReference(this);
+ }
+
+ ///
+ protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference)
+ {
+ return new BaseOpenApiReference(sourceReference);
+ }
+ }
+}
diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
index 8b5868216..3bf31c509 100644
--- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
+++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
@@ -161,6 +161,7 @@ internal void Walk(OpenApiComponents? components)
WalkDictionary(OpenApiConstants.Links, components.Links, static (self, item, isComponent) => self.Walk(item), isComponent);
WalkDictionary(OpenApiConstants.RequestBodies, components.RequestBodies, static (self, item, isComponent) => self.Walk(item), isComponent);
WalkDictionary(OpenApiConstants.Responses, components.Responses, static (self, item, isComponent) => self.Walk(item), isComponent);
+ WalkDictionary(OpenApiConstants.MediaTypes, components.MediaTypes, static (self, item, isComponent) => self.Walk(item, isComponent), isComponent);
Walk(components as IOpenApiExtensible);
}
@@ -831,6 +832,28 @@ internal void Walk(OpenApiMediaType mediaType)
Walk(mediaType as IOpenApiExtensible);
}
+ ///
+ /// Visits and child objects
+ ///
+ internal void Walk(IOpenApiMediaType mediaType, bool isComponent = false)
+ {
+ if (mediaType == null)
+ {
+ return;
+ }
+
+ if (mediaType is IOpenApiReferenceHolder openApiReferenceHolder)
+ {
+ Walk(openApiReferenceHolder);
+ return;
+ }
+
+ if (mediaType is OpenApiMediaType openApiMediaType)
+ {
+ Walk(openApiMediaType);
+ }
+ }
+
///
/// Visits dictionary of
///
diff --git a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs
index 651d2206c..14c8d2ee4 100644
--- a/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs
+++ b/src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs
@@ -187,6 +187,16 @@ public void RegisterComponents(OpenApiDocument document)
RegisterComponent(location, item.Value);
}
}
+
+ // Register MediaTypes
+ if (document.Components.MediaTypes != null)
+ {
+ foreach (var item in document.Components.MediaTypes)
+ {
+ location = baseUri + ReferenceType.MediaType.GetDisplayName() + ComponentSegmentSeparator + item.Key;
+ RegisterComponent(location, item.Value);
+ }
+ }
}
private static string getBaseUri(OpenApiDocument openApiDocument)
@@ -225,6 +235,7 @@ public bool RegisterComponentForDocument(OpenApiDocument openApiDocument, T c
IOpenApiExample => baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + id,
IOpenApiHeader => baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + id,
IOpenApiSecurityScheme => baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + id,
+ IOpenApiMediaType => baseUri + ReferenceType.MediaType.GetDisplayName() + ComponentSegmentSeparator + id,
_ => throw new ArgumentException($"Invalid component type {componentToRegister!.GetType().Name}"),
};
diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
index fc6560475..e0a83e038 100644
--- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
+++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
@@ -150,6 +150,16 @@ namespace Microsoft.OpenApi
Microsoft.OpenApi.RuntimeExpressionAnyWrapper? RequestBody { get; }
Microsoft.OpenApi.OpenApiServer? Server { get; }
}
+ public interface IOpenApiMediaType : Microsoft.OpenApi.IOpenApiElement, Microsoft.OpenApi.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.IOpenApiReferenceable, Microsoft.OpenApi.IOpenApiSerializable, Microsoft.OpenApi.IShallowCopyable
+ {
+ System.Collections.Generic.IDictionary? Encoding { get; }
+ System.Text.Json.Nodes.JsonNode? Example { get; }
+ System.Collections.Generic.IDictionary? Examples { get; }
+ Microsoft.OpenApi.OpenApiEncoding? ItemEncoding { get; }
+ Microsoft.OpenApi.IOpenApiSchema? ItemSchema { get; }
+ System.Collections.Generic.IList? PrefixEncoding { get; }
+ Microsoft.OpenApi.IOpenApiSchema? Schema { get; }
+ }
public interface IOpenApiParameter : Microsoft.OpenApi.IOpenApiDescribedElement, Microsoft.OpenApi.IOpenApiElement, Microsoft.OpenApi.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.IOpenApiReferenceable, Microsoft.OpenApi.IOpenApiSerializable, Microsoft.OpenApi.IShallowCopyable
{
bool AllowEmptyValue { get; }
@@ -401,6 +411,7 @@ namespace Microsoft.OpenApi
public System.Collections.Generic.IDictionary? Extensions { get; set; }
public System.Collections.Generic.IDictionary? Headers { get; set; }
public System.Collections.Generic.IDictionary? Links { get; set; }
+ public System.Collections.Generic.IDictionary? MediaTypes { get; set; }
public System.Collections.Generic.IDictionary? Parameters { get; set; }
public System.Collections.Generic.IDictionary? PathItems { get; set; }
public System.Collections.Generic.IDictionary? RequestBodies { get; set; }
@@ -501,6 +512,7 @@ namespace Microsoft.OpenApi
public const string MaxLength = "maxLength";
public const string MaxProperties = "maxProperties";
public const string Maximum = "maximum";
+ public const string MediaTypes = "mediaTypes";
public const string MinItems = "minItems";
public const string MinLength = "minLength";
public const string MinProperties = "minProperties";
@@ -895,7 +907,7 @@ namespace Microsoft.OpenApi
public Microsoft.OpenApi.IOpenApiLink CreateShallowCopy() { }
public override void SerializeAsV2(Microsoft.OpenApi.IOpenApiWriter writer) { }
}
- public class OpenApiMediaType : Microsoft.OpenApi.IOpenApiElement, Microsoft.OpenApi.IOpenApiExtensible, Microsoft.OpenApi.IOpenApiSerializable
+ public class OpenApiMediaType : Microsoft.OpenApi.IOpenApiElement, Microsoft.OpenApi.IOpenApiExtensible, Microsoft.OpenApi.IOpenApiMediaType, Microsoft.OpenApi.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.IOpenApiReferenceable, Microsoft.OpenApi.IOpenApiSerializable, Microsoft.OpenApi.IShallowCopyable
{
public OpenApiMediaType() { }
public OpenApiMediaType(Microsoft.OpenApi.OpenApiMediaType? mediaType) { }
@@ -907,11 +919,27 @@ namespace Microsoft.OpenApi
public Microsoft.OpenApi.IOpenApiSchema? ItemSchema { get; set; }
public System.Collections.Generic.IList? PrefixEncoding { get; set; }
public Microsoft.OpenApi.IOpenApiSchema? Schema { get; set; }
+ public Microsoft.OpenApi.IOpenApiMediaType CreateShallowCopy() { }
public virtual void SerializeAsV2(Microsoft.OpenApi.IOpenApiWriter writer) { }
public virtual void SerializeAsV3(Microsoft.OpenApi.IOpenApiWriter writer) { }
public virtual void SerializeAsV31(Microsoft.OpenApi.IOpenApiWriter writer) { }
public virtual void SerializeAsV32(Microsoft.OpenApi.IOpenApiWriter writer) { }
}
+ public class OpenApiMediaTypeReference : Microsoft.OpenApi.BaseOpenApiReferenceHolder, Microsoft.OpenApi.IOpenApiElement, Microsoft.OpenApi.IOpenApiMediaType, Microsoft.OpenApi.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.IOpenApiReferenceable, Microsoft.OpenApi.IOpenApiSerializable, Microsoft.OpenApi.IShallowCopyable
+ {
+ public OpenApiMediaTypeReference(string referenceId, Microsoft.OpenApi.OpenApiDocument? hostDocument = null, string? externalResource = null) { }
+ public System.Collections.Generic.IDictionary? Encoding { get; }
+ public System.Text.Json.Nodes.JsonNode? Example { get; }
+ public System.Collections.Generic.IDictionary? Examples { get; }
+ public System.Collections.Generic.IDictionary? Extensions { get; }
+ public Microsoft.OpenApi.OpenApiEncoding? ItemEncoding { get; }
+ public Microsoft.OpenApi.IOpenApiSchema? ItemSchema { get; }
+ public System.Collections.Generic.IList? PrefixEncoding { get; }
+ public Microsoft.OpenApi.IOpenApiSchema? Schema { get; }
+ protected override Microsoft.OpenApi.BaseOpenApiReference CopyReference(Microsoft.OpenApi.BaseOpenApiReference sourceReference) { }
+ public override Microsoft.OpenApi.IOpenApiMediaType CopyReferenceAsTargetElementWithOverrides(Microsoft.OpenApi.IOpenApiMediaType source) { }
+ public Microsoft.OpenApi.IOpenApiMediaType CreateShallowCopy() { }
+ }
public static class OpenApiNonDefaultRules
{
public static Microsoft.OpenApi.ValidationRule HeaderMismatchedDataType { get; }
@@ -1800,6 +1828,8 @@ namespace Microsoft.OpenApi
Tag = 9,
[Microsoft.OpenApi.Display("pathItems")]
PathItem = 10,
+ [Microsoft.OpenApi.Display("mediaTypes")]
+ MediaType = 11,
}
public sealed class RequestExpression : Microsoft.OpenApi.RuntimeExpression
{
From 41a231eb6bc9734a885dee32900ac47dbeca5450 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Oct 2025 18:45:25 +0000
Subject: [PATCH 03/20] Add comprehensive tests for media types components
support
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
---
.../OpenApiComponentsMediaTypesTests.cs | 230 ++++++++++++++++++
1 file changed, 230 insertions(+)
create mode 100644 test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
new file mode 100644
index 000000000..a1daa9518
--- /dev/null
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
@@ -0,0 +1,230 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license.
+
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.OpenApi.Tests.Models
+{
+ [Collection("DefaultSettings")]
+ public class OpenApiComponentsMediaTypesTests
+ {
+ public static OpenApiComponents ComponentsWithMediaTypes = new()
+ {
+ MediaTypes = new Dictionary()
+ {
+ ["application/json"] = new OpenApiMediaType()
+ {
+ Schema = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.Object,
+ Properties = new Dictionary()
+ {
+ ["name"] = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.String
+ },
+ ["age"] = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.Integer
+ }
+ }
+ }
+ },
+ ["text/plain"] = new OpenApiMediaType()
+ {
+ Schema = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.String
+ }
+ }
+ }
+ };
+
+ [Fact]
+ public async Task SerializeMediaTypesAsV32JsonWorks()
+ {
+ // Arrange
+ var expected =
+ """
+ {
+ "mediaTypes": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "age": {
+ "type": "integer"
+ }
+ }
+ }
+ },
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ """;
+
+ // Act
+ var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_2);
+
+ // Assert
+ actual = actual.MakeLineBreaksEnvironmentNeutral();
+ expected = expected.MakeLineBreaksEnvironmentNeutral();
+ Assert.Equal(expected, actual);
+ }
+
+ [Fact]
+ public async Task SerializeMediaTypesAsV31JsonWorks()
+ {
+ // Arrange - When serializing to v3.1, mediaTypes should be prefixed with x-oai-
+ var expected =
+ """
+ {
+ "x-oai-mediaTypes": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "age": {
+ "type": "integer"
+ }
+ }
+ }
+ },
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ """;
+
+ // Act
+ var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1);
+
+ // Assert
+ actual = actual.MakeLineBreaksEnvironmentNeutral();
+ expected = expected.MakeLineBreaksEnvironmentNeutral();
+ Assert.Equal(expected, actual);
+ }
+
+ [Fact]
+ public async Task SerializeMediaTypesAsV30JsonWorks()
+ {
+ // Arrange - When serializing to v3.0, mediaTypes should be prefixed with x-oai-
+ var expected =
+ """
+ {
+ "x-oai-mediaTypes": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "age": {
+ "type": "integer"
+ }
+ }
+ }
+ },
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ """;
+
+ // Act
+ var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
+
+ // Assert
+ actual = actual.MakeLineBreaksEnvironmentNeutral();
+ expected = expected.MakeLineBreaksEnvironmentNeutral();
+ Assert.Equal(expected, actual);
+ }
+
+ [Fact]
+ public void CopyConstructorCopiesMediaTypes()
+ {
+ // Arrange
+ var original = ComponentsWithMediaTypes;
+
+ // Act
+ var copy = new OpenApiComponents(original);
+
+ // Assert
+ Assert.NotNull(copy.MediaTypes);
+ Assert.Equal(2, copy.MediaTypes.Count);
+ Assert.True(copy.MediaTypes.ContainsKey("application/json"));
+ Assert.True(copy.MediaTypes.ContainsKey("text/plain"));
+ }
+
+ [Fact]
+ public void WorkspaceCanRegisterMediaTypeComponents()
+ {
+ // Arrange
+ var mediaType = new OpenApiMediaType()
+ {
+ Schema = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.Object
+ }
+ };
+
+ var doc = new OpenApiDocument()
+ {
+ Components = new OpenApiComponents()
+ {
+ MediaTypes = new Dictionary()
+ {
+ ["application/json"] = mediaType
+ }
+ }
+ };
+
+ // Act
+ doc.RegisterComponents();
+
+ // Assert
+ Assert.Equal(1, doc.Workspace.ComponentsCount());
+ }
+
+ [Fact]
+ public void WorkspaceCanRegisterMediaTypeForDocument()
+ {
+ // Arrange
+ var mediaType = new OpenApiMediaType()
+ {
+ Schema = new OpenApiSchema()
+ {
+ Type = JsonSchemaType.String
+ }
+ };
+
+ var doc = new OpenApiDocument();
+
+ // Act
+ var result = doc.Workspace.RegisterComponentForDocument(doc, mediaType, "text/plain");
+
+ // Assert
+ Assert.True(result);
+ Assert.Equal(1, doc.Workspace.ComponentsCount());
+ }
+ }
+}
From 9928a7bcd964faaa319fd62d84690dad25425000 Mon Sep 17 00:00:00 2001
From: Vincent Biret
Date: Thu, 2 Oct 2025 15:55:45 -0400
Subject: [PATCH 04/20] chore: partial fix of the walker implementation for
media type support
Signed-off-by: Vincent Biret
---
.../Services/OpenApiVisitorBase.cs | 6 ++--
.../Services/OpenApiWalker.cs | 34 +++++++++----------
.../Validations/OpenApiValidator.cs | 4 +--
.../PublicApi/PublicApi.approved.txt | 8 ++---
.../OpenApiMediaTypeValidationTests.cs | 4 +--
.../Visitors/InheritanceTests.cs | 8 ++---
.../Walkers/WalkerLocationTests.cs | 4 +--
7 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs
index 7aa411b57..397062aca 100644
--- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs
+++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs
@@ -187,14 +187,14 @@ public virtual void Visit(OpenApiResponses response)
///
/// Visits media type content.
///
- public virtual void Visit(IDictionary content)
+ public virtual void Visit(IDictionary content)
{
}
///
- /// Visits
+ /// Visits
///
- public virtual void Visit(OpenApiMediaType mediaType)
+ public virtual void Visit(IOpenApiMediaType mediaType)
{
}
diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
index 3bf31c509..5e4017b28 100644
--- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
+++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
@@ -641,7 +641,7 @@ internal void Walk(IOpenApiParameter parameter, bool isComponent = false)
if (parameter.Content is { } content)
{
- WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
+ WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
}
WalkDictionary(OpenApiConstants.Examples, parameter.Examples, static (self, item, isComponent) => self.Walk(item, isComponent));
@@ -696,7 +696,7 @@ internal void Walk(IOpenApiResponse response, bool isComponent = false)
if (response.Content is { } content)
{
- WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
+ WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
}
WalkDictionary(OpenApiConstants.Links, response.Links, static (self, item, isComponent) => self.Walk(item, isComponent));
@@ -724,7 +724,7 @@ internal void Walk(IOpenApiRequestBody? requestBody, bool isComponent = false)
if (requestBody.Content is { } content)
{
- WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
+ WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
}
Walk(requestBody as IOpenApiExtensible);
@@ -781,9 +781,9 @@ internal void Walk(IDictionary? callbacks)
}
///
- /// Visits dictionary of
+ /// Visits dictionary of
///
- internal void Walk(IDictionary? content)
+ internal void Walk(IDictionary? content)
{
if (content == null)
{
@@ -806,9 +806,9 @@ internal void Walk(IDictionary? content)
}
///
- /// Visits and child objects
+ /// Visits and child objects
///
- internal void Walk(OpenApiMediaType mediaType)
+ internal void Walk(IOpenApiMediaType mediaType)
{
if (mediaType == null)
{
@@ -850,7 +850,7 @@ internal void Walk(IOpenApiMediaType mediaType, bool isComponent = false)
if (mediaType is OpenApiMediaType openApiMediaType)
{
- Walk(openApiMediaType);
+ Walk((IOpenApiMediaType)openApiMediaType);
}
}
@@ -1187,7 +1187,7 @@ internal void Walk(IOpenApiHeader header, bool isComponent = false)
if (header.Content is { } content)
{
- WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
+ WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
}
if (header.Example is { } example)
@@ -1273,27 +1273,25 @@ internal void Walk(IOpenApiElement element)
case IOpenApiCallback e: Walk(e); break;
case OpenApiEncoding e: Walk(e); break;
case IOpenApiExample e: Walk(e); break;
- case Dictionary e: Walk(e); break;
case OpenApiExternalDocs e: Walk(e); break;
- case OpenApiHeader e: Walk(e); break;
- case OpenApiLink e: Walk(e); break;
- case Dictionary e: Walk(e); break;
- case OpenApiMediaType e: Walk(e); break;
+ case IOpenApiHeader e: Walk(e); break;
+ case IOpenApiLink e: Walk(e); break;
+ case IOpenApiMediaType e: Walk(e); break;
case OpenApiOAuthFlows e: Walk(e); break;
case OpenApiOAuthFlow e: Walk(e); break;
case OpenApiOperation e: Walk(e); break;
case IOpenApiParameter e: Walk(e); break;
case OpenApiPaths e: Walk(e); break;
+ case IOpenApiPathItem e: Walk(e); break;
case OpenApiRequestBody e: Walk(e); break;
- case OpenApiResponse e: Walk(e); break;
- case OpenApiSchema e: Walk(e); break;
+ case IOpenApiResponse e: Walk(e); break;
+ case IOpenApiSchema e: Walk(e); break;
case OpenApiDiscriminator e: Walk(e); break;
case OpenApiSecurityRequirement e: Walk(e); break;
- case OpenApiSecurityScheme e: Walk(e); break;
+ case IOpenApiSecurityScheme e: Walk(e); break;
case OpenApiServer e: Walk(e); break;
case OpenApiServerVariable e: Walk(e); break;
case OpenApiTag e: Walk(e); break;
- case HashSet e: Walk(e); break;
case IOpenApiExtensible e: Walk(e); break;
case IOpenApiExtension e: Walk(e); break;
}
diff --git a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs
index 7903298ce..022bbbe3e 100644
--- a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs
+++ b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs
@@ -77,7 +77,7 @@ public void AddWarning(OpenApiValidatorWarning warning)
public override void Visit(IOpenApiResponse response) => Validate(response);
///
- public override void Visit(OpenApiMediaType mediaType) => Validate(mediaType);
+ public override void Visit(IOpenApiMediaType mediaType) => Validate(mediaType);
///
public override void Visit(OpenApiResponses response) => Validate(response);
@@ -151,7 +151,7 @@ public void AddWarning(OpenApiValidatorWarning warning)
///
public override void Visit(IDictionary callbacks) => Validate(callbacks, callbacks.GetType());
///
- public override void Visit(IDictionary content) => Validate(content, content.GetType());
+ public override void Visit(IDictionary content) => Validate(content, content.GetType());
///
public override void Visit(IDictionary examples) => Validate(examples, examples.GetType());
///
diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
index 6a08425a5..683a7b685 100644
--- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
+++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
@@ -1519,6 +1519,7 @@ namespace Microsoft.OpenApi
public override void Visit(Microsoft.OpenApi.IOpenApiExtension openApiExtension) { }
public override void Visit(Microsoft.OpenApi.IOpenApiHeader header) { }
public override void Visit(Microsoft.OpenApi.IOpenApiLink link) { }
+ public override void Visit(Microsoft.OpenApi.IOpenApiMediaType mediaType) { }
public override void Visit(Microsoft.OpenApi.IOpenApiParameter parameter) { }
public override void Visit(Microsoft.OpenApi.IOpenApiPathItem pathItem) { }
public override void Visit(Microsoft.OpenApi.IOpenApiRequestBody requestBody) { }
@@ -1532,7 +1533,6 @@ namespace Microsoft.OpenApi
public override void Visit(Microsoft.OpenApi.OpenApiExternalDocs externalDocs) { }
public override void Visit(Microsoft.OpenApi.OpenApiInfo info) { }
public override void Visit(Microsoft.OpenApi.OpenApiLicense license) { }
- public override void Visit(Microsoft.OpenApi.OpenApiMediaType mediaType) { }
public override void Visit(Microsoft.OpenApi.OpenApiOAuthFlow openApiOAuthFlow) { }
public override void Visit(Microsoft.OpenApi.OpenApiOperation operation) { }
public override void Visit(Microsoft.OpenApi.OpenApiPaths paths) { }
@@ -1546,8 +1546,8 @@ namespace Microsoft.OpenApi
public override void Visit(System.Collections.Generic.IDictionary examples) { }
public override void Visit(System.Collections.Generic.IDictionary headers) { }
public override void Visit(System.Collections.Generic.IDictionary links) { }
+ public override void Visit(System.Collections.Generic.IDictionary content) { }
public override void Visit(System.Collections.Generic.IDictionary encodings) { }
- public override void Visit(System.Collections.Generic.IDictionary content) { }
public override void Visit(System.Collections.Generic.IDictionary serverVariables) { }
public override void Visit(System.Collections.Generic.List example) { }
}
@@ -1574,6 +1574,7 @@ namespace Microsoft.OpenApi
public virtual void Visit(Microsoft.OpenApi.IOpenApiExtension openApiExtension) { }
public virtual void Visit(Microsoft.OpenApi.IOpenApiHeader header) { }
public virtual void Visit(Microsoft.OpenApi.IOpenApiLink link) { }
+ public virtual void Visit(Microsoft.OpenApi.IOpenApiMediaType mediaType) { }
public virtual void Visit(Microsoft.OpenApi.IOpenApiParameter parameter) { }
public virtual void Visit(Microsoft.OpenApi.IOpenApiPathItem pathItem) { }
public virtual void Visit(Microsoft.OpenApi.IOpenApiReferenceHolder referenceHolder) { }
@@ -1588,7 +1589,6 @@ namespace Microsoft.OpenApi
public virtual void Visit(Microsoft.OpenApi.OpenApiExternalDocs externalDocs) { }
public virtual void Visit(Microsoft.OpenApi.OpenApiInfo info) { }
public virtual void Visit(Microsoft.OpenApi.OpenApiLicense license) { }
- public virtual void Visit(Microsoft.OpenApi.OpenApiMediaType mediaType) { }
public virtual void Visit(Microsoft.OpenApi.OpenApiOAuthFlow openApiOAuthFlow) { }
public virtual void Visit(Microsoft.OpenApi.OpenApiOperation operation) { }
public virtual void Visit(Microsoft.OpenApi.OpenApiPaths paths) { }
@@ -1603,9 +1603,9 @@ namespace Microsoft.OpenApi
public virtual void Visit(System.Collections.Generic.IDictionary examples) { }
public virtual void Visit(System.Collections.Generic.IDictionary headers) { }
public virtual void Visit(System.Collections.Generic.IDictionary links) { }
+ public virtual void Visit(System.Collections.Generic.IDictionary content) { }
public virtual void Visit(System.Collections.Generic.IDictionary webhooks) { }
public virtual void Visit(System.Collections.Generic.IDictionary encodings) { }
- public virtual void Visit(System.Collections.Generic.IDictionary content) { }
public virtual void Visit(System.Collections.Generic.IDictionary serverVariables) { }
public virtual void Visit(System.Collections.Generic.IList parameters) { }
public virtual void Visit(System.Collections.Generic.IList openApiSecurityRequirements) { }
diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs
index 3d45e77f5..277ef6986 100644
--- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs
@@ -28,7 +28,7 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
var validator = new OpenApiValidator(ruleset);
var walker = new OpenApiWalker(validator);
- walker.Walk(mediaType);
+ walker.Walk((IOpenApiMediaType)mediaType);
warnings = validator.Warnings;
var result = !warnings.Any();
@@ -87,7 +87,7 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
var validator = new OpenApiValidator(ruleset);
var walker = new OpenApiWalker(validator);
- walker.Walk(mediaType);
+ walker.Walk((IOpenApiMediaType)mediaType);
warnings = validator.Warnings;
var result = !warnings.Any();
diff --git a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs
index 25f917c9d..54af7e917 100644
--- a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs
@@ -33,8 +33,8 @@ public void ExpectedVirtualsInvolved()
visitor.Visit(default(Dictionary));
visitor.Visit(default(IOpenApiResponse));
visitor.Visit(default(OpenApiResponses));
- visitor.Visit(default(Dictionary));
- visitor.Visit(default(OpenApiMediaType));
+ visitor.Visit(default(Dictionary));
+ visitor.Visit(default(IOpenApiMediaType));
visitor.Visit(default(OpenApiEncoding));
visitor.Visit(default(Dictionary));
visitor.Visit(default(OpenApiComponents));
@@ -192,13 +192,13 @@ public override void Visit(OpenApiResponses response)
base.Visit(response);
}
- public override void Visit(IDictionary content)
+ public override void Visit(IDictionary content)
{
EncodeCall();
base.Visit(content);
}
- public override void Visit(OpenApiMediaType mediaType)
+ public override void Visit(IOpenApiMediaType mediaType)
{
EncodeCall();
base.Visit(mediaType);
diff --git a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs
index 60ea86e4a..e7ae74119 100644
--- a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs
@@ -297,12 +297,12 @@ public override void Visit(IOpenApiReferenceHolder referenceable)
{
Locations.Add("referenceAt: " + this.PathString);
}
- public override void Visit(IDictionary content)
+ public override void Visit(IDictionary content)
{
Locations.Add(this.PathString);
}
- public override void Visit(OpenApiMediaType mediaType)
+ public override void Visit(IOpenApiMediaType mediaType)
{
Keys.Add(CurrentKeys.Content);
Locations.Add(this.PathString);
From 34613320bd48cd0419fc3fe286d3e27a2878ac2c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 2 Oct 2025 20:05:33 +0000
Subject: [PATCH 05/20] Address code review feedback: use inheritdoc and
StringComparer.Ordinal
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
---
.../Models/OpenApiMediaType.cs | 52 +++++--------------
1 file changed, 14 insertions(+), 38 deletions(-)
diff --git a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
index c9ceb9284..7adcb21a6 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiMediaType.cs
@@ -13,47 +13,25 @@ namespace Microsoft.OpenApi
///
public class OpenApiMediaType : IOpenApiSerializable, IOpenApiExtensible, IOpenApiMediaType
{
- ///
- /// The schema defining the type used for the request body.
- ///
+ ///
public IOpenApiSchema? Schema { get; set; }
- ///
- /// The schema defining the type used for the items in an array media type.
- /// This property is only applicable for OAS 3.2.0 and later.
- ///
+ ///
public IOpenApiSchema? ItemSchema { get; set; }
- ///
- /// Example of the media type.
- /// The example object SHOULD be in the correct format as specified by the media type.
- ///
+ ///
public JsonNode? Example { get; set; }
- ///
- /// Examples of the media type.
- /// Each example object SHOULD match the media type and specified schema if present.
- ///
+ ///
public IDictionary? Examples { get; set; }
- ///
- /// A map between a property name and its encoding information.
- /// The key, being the property name, MUST exist in the schema as a property.
- /// The encoding object SHALL only apply to requestBody objects
- /// when the media type is multipart or application/x-www-form-urlencoded.
- ///
+ ///
public IDictionary? Encoding { get; set; }
- ///
- /// An encoding object for items in an array schema.
- /// Only applies when the schema is of type array.
- ///
+ ///
public OpenApiEncoding? ItemEncoding { get; set; }
- ///
- /// An array of encoding objects for prefixItems in an array schema.
- /// Each element corresponds to a prefixItem in the schema.
- ///
+ ///
public IList? PrefixEncoding { get; set; }
///
@@ -74,11 +52,11 @@ public OpenApiMediaType(OpenApiMediaType? mediaType)
Schema = mediaType?.Schema?.CreateShallowCopy();
ItemSchema = mediaType?.ItemSchema?.CreateShallowCopy();
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;
+ Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples, StringComparer.Ordinal) : null;
+ Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding, StringComparer.Ordinal) : null;
ItemEncoding = mediaType?.ItemEncoding != null ? new OpenApiEncoding(mediaType.ItemEncoding) : null;
PrefixEncoding = mediaType?.PrefixEncoding != null ? new List(mediaType.PrefixEncoding.Select(e => new OpenApiEncoding(e))) : null;
- Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null;
+ Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions, StringComparer.Ordinal) : null;
}
///
@@ -89,16 +67,14 @@ internal OpenApiMediaType(IOpenApiMediaType mediaType)
Schema = mediaType?.Schema?.CreateShallowCopy();
ItemSchema = mediaType?.ItemSchema?.CreateShallowCopy();
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;
+ Examples = mediaType?.Examples != null ? new Dictionary(mediaType.Examples, StringComparer.Ordinal) : null;
+ Encoding = mediaType?.Encoding != null ? new Dictionary(mediaType.Encoding, StringComparer.Ordinal) : null;
ItemEncoding = mediaType?.ItemEncoding != null ? new OpenApiEncoding(mediaType.ItemEncoding) : null;
PrefixEncoding = mediaType?.PrefixEncoding != null ? new List(mediaType.PrefixEncoding.Select(e => new OpenApiEncoding(e))) : null;
- Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions) : null;
+ Extensions = mediaType?.Extensions != null ? new Dictionary(mediaType.Extensions, StringComparer.Ordinal) : null;
}
- ///
- /// Creates a shallow copy of this object
- ///
+ ///
public IOpenApiMediaType CreateShallowCopy()
{
return new OpenApiMediaType(this);
From 02cf2b87643981a3a5213b178984113fb47ede9e Mon Sep 17 00:00:00 2001
From: Vincent Biret
Date: Thu, 2 Oct 2025 20:21:54 -0400
Subject: [PATCH 06/20] chore: use json node deep equals for comparison
Signed-off-by: Vincent Biret
---
.../Models/OpenApiComponentsMediaTypesTests.cs | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
index a1daa9518..3f5d28e50 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsMediaTypesTests.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using System.Collections.Generic;
+using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Xunit;
@@ -76,9 +77,7 @@ public async Task SerializeMediaTypesAsV32JsonWorks()
var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_2);
// Assert
- actual = actual.MakeLineBreaksEnvironmentNeutral();
- expected = expected.MakeLineBreaksEnvironmentNeutral();
- Assert.Equal(expected, actual);
+ Assert.True(JsonNode.DeepEquals(JsonNode.Parse(expected), JsonNode.Parse(actual)));
}
[Fact]
@@ -115,9 +114,7 @@ public async Task SerializeMediaTypesAsV31JsonWorks()
var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
- actual = actual.MakeLineBreaksEnvironmentNeutral();
- expected = expected.MakeLineBreaksEnvironmentNeutral();
- Assert.Equal(expected, actual);
+ Assert.True(JsonNode.DeepEquals(JsonNode.Parse(expected), JsonNode.Parse(actual)));
}
[Fact]
@@ -154,9 +151,7 @@ public async Task SerializeMediaTypesAsV30JsonWorks()
var actual = await ComponentsWithMediaTypes.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
- actual = actual.MakeLineBreaksEnvironmentNeutral();
- expected = expected.MakeLineBreaksEnvironmentNeutral();
- Assert.Equal(expected, actual);
+ Assert.True(JsonNode.DeepEquals(JsonNode.Parse(expected), JsonNode.Parse(actual)));
}
[Fact]
From 834e41ff2ae9c5f991fc9075d5b549adb8d08fd3 Mon Sep 17 00:00:00 2001
From: Vincent Biret
Date: Thu, 2 Oct 2025 21:08:49 -0400
Subject: [PATCH 07/20] feat: make response request body, header and parameter
content referenceable
Signed-off-by: Vincent Biret
---
.../Models/Interfaces/IOpenApiHeader.cs | 2 +-
.../Models/Interfaces/IOpenApiParameter.cs | 2 +-
.../Models/Interfaces/IOpenApiRequestBody.cs | 2 +-
.../Models/Interfaces/IOpenApiResponse.cs | 2 +-
src/Microsoft.OpenApi/Models/OpenApiHeader.cs | 4 +-
.../Models/OpenApiParameter.cs | 4 +-
.../Models/OpenApiRequestBody.cs | 4 +-
.../Models/OpenApiResponse.cs | 4 +-
.../References/OpenApiHeaderReference.cs | 2 +-
.../References/OpenApiParameterReference.cs | 2 +-
.../References/OpenApiRequestBodyReference.cs | 2 +-
.../References/OpenApiResponseReference.cs | 2 +-
.../Reader/V2/OpenApiDocumentDeserializer.cs | 2 +-
.../Reader/V2/OpenApiOperationDeserializer.cs | 4 +-
.../Reader/V2/OpenApiResponseDeserializer.cs | 19 +--
.../Reader/V3/OpenApiMediaTypeDeserializer.cs | 2 +-
.../V31/OpenApiMediaTypeDeserializer.cs | 2 +-
.../V32/OpenApiMediaTypeDeserializer.cs | 2 +-
.../Services/OpenApiWalker.cs | 8 +-
.../Formatters/PowerShellFormatterTests.cs | 2 +-
.../UtilityFiles/OpenApiDocumentMock.cs | 20 ++--
.../TryLoadReferenceV2Tests.cs | 8 +-
.../V2Tests/OpenApiDocumentTests.cs | 12 +-
.../V2Tests/OpenApiOperationTests.cs | 12 +-
.../V2Tests/OpenApiPathItemTests.cs | 30 ++---
.../V31Tests/OpenApiDocumentTests.cs | 12 +-
.../V31Tests/RelativeReferenceTests.cs | 2 +-
.../V32Tests/OpenApiDocumentTests.cs | 12 +-
.../V32Tests/RelativeReferenceTests.cs | 2 +-
.../V3Tests/OpenApiCallbackTests.cs | 10 +-
.../V3Tests/OpenApiDocumentTests.cs | 50 ++++----
.../V3Tests/OpenApiParameterTests.cs | 4 +-
.../Mocks/OpenApiDocumentMock.cs | 16 +--
.../OpenApiMediaTypeSerializationTests.cs | 2 +-
.../Models/OpenApiCallbackTests.cs | 8 +-
.../Models/OpenApiComponentsTests.cs | 2 +-
.../Models/OpenApiDocumentTests.cs | 112 +++++++++---------
.../Models/OpenApiOperationTests.cs | 22 ++--
.../Models/OpenApiPathItemTests.cs | 6 +-
.../Models/OpenApiRequestBodyTests.cs | 8 +-
.../Models/OpenApiResponseTests.cs | 10 +-
.../PublicApi/PublicApi.approved.txt | 24 ++--
.../OpenApiDocumentValidationTests.cs | 6 +-
.../OpenApiRecommendedRulesTests.cs | 22 ++--
.../OpenApiReferenceValidationTests.cs | 8 +-
.../Walkers/WalkerLocationTests.cs | 8 +-
.../Workspaces/OpenApiWorkspaceTests.cs | 2 +-
.../Writers/OpenApiYamlWriterTests.cs | 4 +-
48 files changed, 254 insertions(+), 253 deletions(-)
diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs
index 46f8666aa..9d33adb46 100644
--- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs
+++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiHeader.cs
@@ -59,6 +59,6 @@ public interface IOpenApiHeader : IOpenApiDescribedElement, IOpenApiReadOnlyExte
///
/// A map containing the representations for the header.
///
- public IDictionary? Content { get; }
+ public IDictionary? Content { get; }
}
diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs
index 17db255df..b71fc979d 100644
--- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs
+++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiParameter.cs
@@ -101,5 +101,5 @@ public interface IOpenApiParameter : IOpenApiDescribedElement, IOpenApiReadOnlyE
/// When example or examples are provided in conjunction with the schema object,
/// the example MUST follow the prescribed serialization strategy for the parameter.
///
- public IDictionary? Content { get; }
+ public IDictionary? Content { get; }
}
diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs
index dfe1e1715..5ab2f7174 100644
--- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs
+++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiRequestBody.cs
@@ -17,7 +17,7 @@ public interface IOpenApiRequestBody : IOpenApiDescribedElement, IOpenApiReadOnl
/// REQUIRED. The content of the request body. The key is a media type or media type range and the value describes it.
/// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
///
- public IDictionary? Content { get; }
+ public IDictionary? Content { get; }
///
/// Converts the request body to a body parameter in preparation for a v2 serialization.
///
diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs
index e8b8357fe..d0423771f 100644
--- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs
+++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiResponse.cs
@@ -17,7 +17,7 @@ public interface IOpenApiResponse : IOpenApiDescribedElement, IOpenApiReadOnlyEx
/// A map containing descriptions of potential response payloads.
/// The key is a media type or media type range and the value describes it.
///
- public IDictionary? Content { get; }
+ public IDictionary? Content { get; }
///
/// A map of operations links that can be followed from the response.
diff --git a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs
index 3165730f0..7e5ea273f 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiHeader.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiHeader.cs
@@ -44,7 +44,7 @@ public class OpenApiHeader : IOpenApiHeader, IOpenApiExtensible
public IDictionary? Examples { get; set; }
///
- public IDictionary? Content { get; set; }
+ public IDictionary? Content { get; set; }
///
public IDictionary? Extensions { get; set; }
@@ -70,7 +70,7 @@ internal OpenApiHeader(IOpenApiHeader header)
Schema = header.Schema?.CreateShallowCopy();
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;
+ Content = header.Content != null ? new Dictionary(header.Content) : null;
Extensions = header.Extensions != null ? new Dictionary(header.Extensions) : null;
}
diff --git a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs
index 919fef46a..d6b060a78 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiParameter.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiParameter.cs
@@ -61,7 +61,7 @@ public bool Explode
public JsonNode? Example { get; set; }
///
- public IDictionary? Content { get; set; }
+ public IDictionary? Content { get; set; }
///
public IDictionary? Extensions { get; set; }
@@ -87,7 +87,7 @@ internal OpenApiParameter(IOpenApiParameter parameter)
Schema = parameter.Schema?.CreateShallowCopy();
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;
+ Content = parameter.Content != null ? new Dictionary(parameter.Content) : null;
Extensions = parameter.Extensions != null ? new Dictionary(parameter.Extensions) : null;
AllowEmptyValue = parameter.AllowEmptyValue;
Deprecated = parameter.Deprecated;
diff --git a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
index 844303f0b..fa29d3ea0 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
@@ -19,7 +19,7 @@ public class OpenApiRequestBody : IOpenApiExtensible, IOpenApiRequestBody
public bool Required { get; set; }
///
- public IDictionary? Content { get; set; }
+ public IDictionary? Content { get; set; }
///
public IDictionary? Extensions { get; set; }
@@ -37,7 +37,7 @@ internal OpenApiRequestBody(IOpenApiRequestBody requestBody)
Utils.CheckArgumentNull(requestBody);
Description = requestBody.Description ?? Description;
Required = requestBody.Required;
- Content = requestBody.Content != null ? new Dictionary(requestBody.Content) : null;
+ Content = requestBody.Content != null ? new Dictionary(requestBody.Content) : null;
Extensions = requestBody.Extensions != null ? new Dictionary(requestBody.Extensions) : null;
}
diff --git a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs
index 68ff27fc5..4ee39336e 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiResponse.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiResponse.cs
@@ -22,7 +22,7 @@ public class OpenApiResponse : IOpenApiExtensible, IOpenApiResponse
public IDictionary? Headers { get; set; }
///
- public IDictionary? Content { get; set; }
+ public IDictionary? Content { get; set; }
///
public IDictionary? Links { get; set; }
@@ -44,7 +44,7 @@ internal OpenApiResponse(IOpenApiResponse response)
Summary = response.Summary ?? Summary;
Description = response.Description ?? Description;
Headers = response.Headers != null ? new Dictionary(response.Headers) : null;
- Content = response.Content != null ? new Dictionary(response.Content) : 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;
}
diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs
index 838b029d4..d0c7fe04e 100644
--- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs
+++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs
@@ -68,7 +68,7 @@ public string? Description
public IDictionary? Examples { get => Target?.Examples; }
///
- public IDictionary? Content { get => Target?.Content; }
+ public IDictionary? Content { get => Target?.Content; }
///
public IDictionary? Extensions { get => Target?.Extensions; }
diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs
index 665669ea2..3c9670ac5 100644
--- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs
+++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs
@@ -74,7 +74,7 @@ public string? Description
public bool Explode { get => Target?.Explode ?? default; }
///
- public IDictionary? Content { get => Target?.Content; }
+ public IDictionary? Content { get => Target?.Content; }
///
public IDictionary? Extensions { get => Target?.Extensions; }
diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs
index a23d325d7..f700f1bc9 100644
--- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs
+++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs
@@ -41,7 +41,7 @@ public string? Description
}
///
- public IDictionary? Content { get => Target?.Content; }
+ public IDictionary? Content { get => Target?.Content; }
///
public bool Required { get => Target?.Required ?? false; }
diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs
index 3133e7054..b99922e79 100644
--- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs
+++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs
@@ -47,7 +47,7 @@ public string? Description
}
///
- public IDictionary? Content { get => Target?.Content; }
+ public IDictionary? Content { get => Target?.Content; }
///
public IDictionary? Headers { get => Target?.Headers; }
diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs
index fc981bf7e..3de0b24a0 100644
--- a/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiDocumentDeserializer.cs
@@ -270,7 +270,7 @@ private static void ProcessResponsesMediaTypes(MapNode mapNode, IEnumerable())
{
ProcessAnyFields(mapNode, mediaType, _mediaTypeAnyFields);
}
diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs
index 4adf036ba..b30073426 100644
--- a/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs
@@ -199,7 +199,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List k,
- _ => mediaType)
+ _ => (IOpenApiMediaType)mediaType)
};
foreach (var value in formBody.Content.Values
@@ -228,7 +228,7 @@ internal static IOpenApiRequestBody CreateRequestBody(
Required = bodyParameter.Required,
Content = consumes.ToDictionary(
k => k,
- _ => new OpenApiMediaType
+ _ => (IOpenApiMediaType)new OpenApiMediaType
{
Schema = bodyParameter.Schema,
Examples = bodyParameter.Examples
diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs
index 07a1d7949..7a474d3fc 100644
--- a/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
namespace Microsoft.OpenApi.Reader.V2
{
@@ -57,11 +58,11 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
{
if (response.Content == null)
{
- response.Content = new Dictionary();
+ response.Content = new Dictionary();
}
else if (context.GetFromTempStorage(TempStorageKeys.ResponseProducesSet, response))
{
- // Process "produces" only once since once specified at operation level it cannot be overriden.
+ // Process "produces" only once since once specified at operation level it cannot be overridden.
return;
}
@@ -74,12 +75,12 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
foreach (var produce in produces)
{
- if (response.Content.TryGetValue(produce, out var produceValue))
+ if (response.Content.TryGetValue(produce, out var produceValue) && produceValue is OpenApiMediaType openApiMediaType)
{
if (schema != null)
{
- produceValue.Schema = schema;
- ProcessAnyFields(mapNode, produceValue, _mediaTypeAnyFields);
+ openApiMediaType.Schema = schema;
+ ProcessAnyFields(mapNode, openApiMediaType, _mediaTypeAnyFields);
}
}
else
@@ -154,12 +155,12 @@ private static void LoadExample(OpenApiResponse response, string mediaType, Pars
{
var exampleNode = node.CreateAny();
- response.Content ??= new Dictionary();
+ response.Content ??= new Dictionary();
OpenApiMediaType mediaTypeObject;
- if (response.Content.TryGetValue(mediaType, out var value))
+ if (response.Content.TryGetValue(mediaType, out var value) && value is OpenApiMediaType mediaTypeValue)
{
- mediaTypeObject = value;
+ mediaTypeObject = mediaTypeValue;
}
else
{
@@ -192,7 +193,7 @@ public static IOpenApiResponse LoadResponse(ParseNode node, OpenApiDocument host
}
if (response.Content?.Values is not null)
{
- foreach (var mediaType in response.Content.Values)
+ foreach (var mediaType in response.Content.Values.OfType())
{
if (mediaType.Schema != null)
{
diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs
index 0d99ff79c..ca334f4cb 100644
--- a/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs
@@ -81,7 +81,7 @@ internal static partial class OpenApiV3Deserializer
}
};
- public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
+ public static IOpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode(OpenApiConstants.Content);
diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs
index 884e6bc6e..89c5e5f85 100644
--- a/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiMediaTypeDeserializer.cs
@@ -91,7 +91,7 @@ internal static partial class OpenApiV31Deserializer
}
};
- public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
+ public static IOpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode(OpenApiConstants.Content);
diff --git a/src/Microsoft.OpenApi/Reader/V32/OpenApiMediaTypeDeserializer.cs b/src/Microsoft.OpenApi/Reader/V32/OpenApiMediaTypeDeserializer.cs
index 1a1961610..cd0df40b6 100644
--- a/src/Microsoft.OpenApi/Reader/V32/OpenApiMediaTypeDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V32/OpenApiMediaTypeDeserializer.cs
@@ -86,7 +86,7 @@ internal static partial class OpenApiV32Deserializer
}
};
- public static OpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
+ public static IOpenApiMediaType LoadMediaType(ParseNode node, OpenApiDocument hostDocument)
{
var mapNode = node.CheckMapNode(OpenApiConstants.Content);
diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
index 5e4017b28..054cde85f 100644
--- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
+++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs
@@ -641,7 +641,7 @@ internal void Walk(IOpenApiParameter parameter, bool isComponent = false)
if (parameter.Content is { } content)
{
- WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
+ WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
}
WalkDictionary(OpenApiConstants.Examples, parameter.Examples, static (self, item, isComponent) => self.Walk(item, isComponent));
@@ -696,7 +696,7 @@ internal void Walk(IOpenApiResponse response, bool isComponent = false)
if (response.Content is { } content)
{
- WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
+ WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
}
WalkDictionary(OpenApiConstants.Links, response.Links, static (self, item, isComponent) => self.Walk(item, isComponent));
@@ -724,7 +724,7 @@ internal void Walk(IOpenApiRequestBody? requestBody, bool isComponent = false)
if (requestBody.Content is { } content)
{
- WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
+ WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
}
Walk(requestBody as IOpenApiExtensible);
@@ -1187,7 +1187,7 @@ internal void Walk(IOpenApiHeader header, bool isComponent = false)
if (header.Content is { } content)
{
- WalkDictionary(OpenApiConstants.Content, content, static (self, item, isComponent) => self.Walk(item, isComponent));
+ WalkItem(OpenApiConstants.Content, content, static (self, item) => self.Walk(item));
}
if (header.Example is { } example)
diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs
index 2fa6a86d4..6b601a2f5 100644
--- a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs
+++ b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs
@@ -120,7 +120,7 @@ private static OpenApiDocument GetSampleOpenApiDocument()
{
Name = "ids",
In = ParameterLocation.Query,
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
"application/json",
diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs
index da3821c56..4654b43b6 100644
--- a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs
+++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs
@@ -92,7 +92,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Success",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -153,7 +153,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Success",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -201,7 +201,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Retrieved entities",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -247,7 +247,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Retrieved entity",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -310,7 +310,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Retrieved navigation property",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -357,7 +357,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Success",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -414,7 +414,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Retrieved navigation property",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -545,7 +545,7 @@ public static OpenApiDocument CreateOpenApiDocument()
"200", new OpenApiResponse()
{
Description = "Success",
- Content = new Dictionary()
+ Content = new Dictionary()
{
{
applicationJsonMediaType,
@@ -679,8 +679,8 @@ public static OpenApiDocument CreateOpenApiDocument()
document.Paths[eventsDeltaPath].Operations![HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("groups.Functions", document)};
document.Paths[refPath].Operations![HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("applications.directoryObject", document)};
((OpenApiSchema)document.Paths[usersPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.user", document);
- document.Paths[usersByIdPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.user", document);
- document.Paths[messagesByIdPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.message", document);
+ ((OpenApiMediaType)document.Paths[usersByIdPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType]).Schema = new OpenApiSchemaReference("microsoft.graph.user", document);
+ ((OpenApiMediaType)document.Paths[messagesByIdPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType]).Schema = new OpenApiSchemaReference("microsoft.graph.message", document);
((OpenApiSchema)document.Paths[securityProfilesPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.networkInterface", document);
((OpenApiSchema)document.Paths[eventsDeltaPath].Operations![HttpMethod.Get].Responses!["200"].Content![applicationJsonMediaType].Schema!.Properties!["value"]).Items = new OpenApiSchemaReference("microsoft.graph.event", document);
return document;
diff --git a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs
index cb9571f42..de41cd81c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/ReferenceService/TryLoadReferenceV2Tests.cs
@@ -69,9 +69,9 @@ public async Task LoadResponseReference()
{
Summary = null,
Description = "Entity not found.",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new()
+ ["application/json"] = new OpenApiMediaType()
}
}, reference
);
@@ -86,9 +86,9 @@ public async Task LoadResponseAndSchemaReference()
var expected = new OpenApiResponse
{
Description = "General Error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new()
+ ["application/json"] = new OpenApiMediaType()
{
Schema = new OpenApiSchemaReference("SampleObject2")
}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
index 36ecdc849..d7368a83a 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs
@@ -146,7 +146,7 @@ public async Task ShouldParseProducesInAnyOrder()
["200"] = new OpenApiResponse()
{
Description = "An OK response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = okMediaType,
["application/xml"] = okMediaType,
@@ -155,7 +155,7 @@ public async Task ShouldParseProducesInAnyOrder()
["default"] = new OpenApiResponse()
{
Description = "An error response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = errorMediaType,
["application/xml"] = errorMediaType
@@ -170,7 +170,7 @@ public async Task ShouldParseProducesInAnyOrder()
["200"] = new OpenApiResponse()
{
Description = "An OK response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["html/text"] = okMediaType
}
@@ -178,7 +178,7 @@ public async Task ShouldParseProducesInAnyOrder()
["default"] = new OpenApiResponse()
{
Description = "An error response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["html/text"] = errorMediaType
}
@@ -192,7 +192,7 @@ public async Task ShouldParseProducesInAnyOrder()
["200"] = new OpenApiResponse()
{
Description = "An OK response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = okMediaType,
["application/xml"] = okMediaType,
@@ -201,7 +201,7 @@ public async Task ShouldParseProducesInAnyOrder()
["default"] = new OpenApiResponse()
{
Description = "An error response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = errorMediaType,
["application/xml"] = errorMediaType
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
index bb7dfca0a..5160f308f 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
@@ -45,7 +45,7 @@ public class OpenApiOperationTests
["200"] = new OpenApiResponse
{
Description = "Pet updated.",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType(),
["application/xml"] = new OpenApiMediaType()
@@ -77,7 +77,7 @@ public class OpenApiOperationTests
{
Description = "Pet to update with",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -97,7 +97,7 @@ public class OpenApiOperationTests
["200"] = new OpenApiResponse
{
Description = "Pet updated.",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType(),
["application/xml"] = new OpenApiMediaType()
@@ -106,7 +106,7 @@ public class OpenApiOperationTests
["405"] = new OpenApiResponse
{
Description = "Invalid input",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType(),
["application/xml"] = new OpenApiMediaType()
@@ -208,7 +208,7 @@ public void ParseOperationWithResponseExamplesShouldSucceed()
{ "200", new OpenApiResponse()
{
Description = "An array of float response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType()
{
@@ -527,7 +527,7 @@ public async Task SerializesBodyReferencesWorks()
openApiDocument.AddComponent("UserRequest", new OpenApiRequestBody
{
Description = "User creation request body",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs
index bc62ac86e..cb41e36b2 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs
@@ -61,9 +61,9 @@ public class OpenApiPathItemTests
],
RequestBody = new OpenApiRequestBody()
{
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/x-www-form-urlencoded"] = new()
+ ["application/x-www-form-urlencoded"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
@@ -87,7 +87,7 @@ public class OpenApiPathItemTests
}
}
},
- ["multipart/form-data"] = new()
+ ["multipart/form-data"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
@@ -118,19 +118,19 @@ public class OpenApiPathItemTests
["200"] = new OpenApiResponse()
{
Description = "Pet updated.",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new(),
- ["application/xml"] = new()
+ ["application/json"] = new OpenApiMediaType(),
+ ["application/xml"] = new OpenApiMediaType()
}
},
["405"] = new OpenApiResponse()
{
Description = "Invalid input",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new(),
- ["application/xml"] = new()
+ ["application/json"] = new OpenApiMediaType(),
+ ["application/xml"] = new OpenApiMediaType()
}
}
}
@@ -167,9 +167,9 @@ public class OpenApiPathItemTests
],
RequestBody = new OpenApiRequestBody()
{
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/x-www-form-urlencoded"] = new()
+ ["application/x-www-form-urlencoded"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
@@ -198,7 +198,7 @@ public class OpenApiPathItemTests
}
}
},
- ["multipart/form-data"] = new()
+ ["multipart/form-data"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
@@ -234,10 +234,10 @@ public class OpenApiPathItemTests
["200"] = new OpenApiResponse()
{
Description = "Pet updated.",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new(),
- ["application/xml"] = new()
+ ["application/json"] = new OpenApiMediaType(),
+ ["application/xml"] = new OpenApiMediaType()
}
}
}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
index c8df6cf99..28085736c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
@@ -149,7 +149,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -177,7 +177,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
{
Description = "Information about a new pet in the system",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -190,7 +190,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "Return a 200 status to indicate that the data was received successfully",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -339,7 +339,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -367,7 +367,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
{
Description = "Information about a new pet in the system",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -380,7 +380,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
["200"] = new OpenApiResponse
{
Description = "Return a 200 status to indicate that the data was received successfully",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/RelativeReferenceTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/RelativeReferenceTests.cs
index 3cae0c533..a8b103e21 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/RelativeReferenceTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/RelativeReferenceTests.cs
@@ -460,7 +460,7 @@ public async Task ShouldResolveReferencesInSchemasFromSystemTextJson()
},
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
index 45403d816..ed868a913 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiDocumentTests.cs
@@ -149,7 +149,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -177,7 +177,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
{
Description = "Information about a new pet in the system",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -190,7 +190,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "Return a 200 status to indicate that the data was received successfully",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -339,7 +339,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -367,7 +367,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
{
Description = "Information about a new pet in the system",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -380,7 +380,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
["200"] = new OpenApiResponse
{
Description = "Return a 200 status to indicate that the data was received successfully",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/RelativeReferenceTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/RelativeReferenceTests.cs
index c2b335ec8..2171f35aa 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V32Tests/RelativeReferenceTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V32Tests/RelativeReferenceTests.cs
@@ -460,7 +460,7 @@ public async Task ShouldResolveReferencesInSchemasFromSystemTextJson()
},
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs
index 1dee79059..e7982160c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs
@@ -37,7 +37,7 @@ public async Task ParseBasicCallbackShouldSucceed()
{
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = null
}
@@ -85,7 +85,7 @@ public async Task ParseCallbackWithReferenceShouldSucceed()
{
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -136,7 +136,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed()
{
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -173,7 +173,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed()
RequestBody = new OpenApiRequestBody
{
Description = "Callback 2",
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -209,7 +209,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed()
{
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/xml"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
index 26cd13a99..2e278ca0e 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
@@ -338,7 +338,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -361,7 +361,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -372,7 +372,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -390,7 +390,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
{
Description = "Pet to add to the store",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -403,7 +403,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -414,7 +414,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -425,7 +425,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -466,7 +466,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -481,7 +481,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -492,7 +492,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -530,7 +530,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -541,7 +541,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -762,7 +762,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -785,7 +785,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -796,7 +796,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -819,7 +819,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
{
Description = "Pet to add to the store",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -832,7 +832,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -843,7 +843,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -854,7 +854,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -907,7 +907,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -922,7 +922,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -933,7 +933,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -971,7 +971,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -982,7 +982,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -1278,7 +1278,7 @@ public async Task SerializesDoubleHopeReferences()
["200"] = new OpenApiResponse
{
Description = "A list of pets",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
index fe1690122..ec4af3cab 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs
@@ -107,9 +107,9 @@ public async Task ParseQueryParameterWithObjectTypeAndContentShouldSucceed()
{
In = ParameterLocation.Query,
Name = "coordinates",
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new()
+ ["application/json"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
diff --git a/test/Microsoft.OpenApi.Tests/Mocks/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Tests/Mocks/OpenApiDocumentMock.cs
index 3b42f1e08..d45eb4d0e 100644
--- a/test/Microsoft.OpenApi.Tests/Mocks/OpenApiDocumentMock.cs
+++ b/test/Microsoft.OpenApi.Tests/Mocks/OpenApiDocumentMock.cs
@@ -39,7 +39,7 @@ public static OpenApiDocument CreateCompleteOpenApiDocument()
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -88,7 +88,7 @@ public static OpenApiDocument CreateCompleteOpenApiDocument()
Value = JsonValue.Create("Fluffy")
}
},
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -141,7 +141,7 @@ public static OpenApiDocument CreateCompleteOpenApiDocument()
],
RequestBody = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -183,7 +183,7 @@ public static OpenApiDocument CreateCompleteOpenApiDocument()
Value = JsonValue.Create("Fluffy")
}
},
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -210,7 +210,7 @@ public static OpenApiDocument CreateCompleteOpenApiDocument()
}
}
},
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -304,7 +304,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["200"] = new OpenApiResponse
{
Description = "A list of pets.",
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -321,7 +321,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
{
["pet"] = new OpenApiRequestBody
{
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
@@ -408,7 +408,7 @@ [new OpenApiSecuritySchemeReference("securitySchemeName2")] =
["200"] = new OpenApiResponse
{
Description = "A list of pets.",
- Content = new Dictionary
+ Content = new Dictionary
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Tests/Mocks/OpenApiMediaTypeSerializationTests.cs b/test/Microsoft.OpenApi.Tests/Mocks/OpenApiMediaTypeSerializationTests.cs
index 6c0f581af..5d2d70399 100644
--- a/test/Microsoft.OpenApi.Tests/Mocks/OpenApiMediaTypeSerializationTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Mocks/OpenApiMediaTypeSerializationTests.cs
@@ -14,7 +14,7 @@ public class OpenApiMediaTypeSerializationTests
public OpenApiMediaTypeSerializationTests()
{
- _mediaType = OpenApiDocumentMock.CreateCompleteOpenApiDocument().Paths["/pets"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"];
+ _mediaType = (OpenApiMediaType)OpenApiDocumentMock.CreateCompleteOpenApiDocument().Paths["/pets"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"];
_mediaType.Schema = _schemaMock.Object;
_mediaType.Examples["cat"] = _exampleMock.Object;
_mediaType.Examples["example"] = _exampleMock.Object;
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
index e6cfa8007..952185498 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
@@ -28,9 +28,9 @@ public class OpenApiCallbackTests
{
RequestBody = new OpenApiRequestBody()
{
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new()
+ ["application/json"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
@@ -68,9 +68,9 @@ public class OpenApiCallbackTests
{
RequestBody = new OpenApiRequestBody()
{
- Content = new Dictionary()
+ Content = new Dictionary()
{
- ["application/json"] = new()
+ ["application/json"] = new OpenApiMediaType()
{
Schema = new OpenApiSchema()
{
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
index 190da253c..792fdab0b 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
@@ -239,7 +239,7 @@ public class OpenApiComponentsTests
RequestBody = new OpenApiRequestBody
{
Description = "Information about a new pet in the system",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
index 396dd1334..f62407b7b 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
@@ -264,7 +264,7 @@ public class OpenApiDocumentTests
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -287,7 +287,7 @@ public class OpenApiDocumentTests
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -298,7 +298,7 @@ public class OpenApiDocumentTests
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -316,7 +316,7 @@ public class OpenApiDocumentTests
{
Description = "Pet to add to the store",
Required = true,
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -329,7 +329,7 @@ public class OpenApiDocumentTests
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["application/json"] = new OpenApiMediaType
{
@@ -340,7 +340,7 @@ public class OpenApiDocumentTests
["4XX"] = new OpenApiResponse
{
Description = "unexpected client error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -351,7 +351,7 @@ public class OpenApiDocumentTests
["5XX"] = new OpenApiResponse
{
Description = "unexpected server error",
- Content = new Dictionary()
+ Content = new Dictionary()
{
["text/html"] = new OpenApiMediaType
{
@@ -392,7 +392,7 @@ public class OpenApiDocumentTests
["200"] = new OpenApiResponse
{
Description = "pet response",
- Content = new Dictionary()
+ Content = new Dictionary