forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for media types components in OAS 3.2.0 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
baywet
merged 23 commits into
feat/oai-3-2-support
from
copilot/fix-1e80ce48-c500-4024-9aa8-a50a721fd288
Oct 3, 2025
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
161605f
Initial plan
Copilot 31b3821
Add support for media types components in OAS 3.2.0
Copilot 41a231e
Add comprehensive tests for media types components support
Copilot c1a7106
Merge branch 'feat/oai-3-2-support' into copilot/fix-1e80ce48-c500-40…
baywet 9928a7b
chore: partial fix of the walker implementation for media type support
baywet 3461332
Address code review feedback: use inheritdoc and StringComparer.Ordinal
Copilot 02cf2b8
chore: use json node deep equals for comparison
baywet 834e41f
feat: make response request body, header and parameter content refere…
baywet fda6621
Add media type reference tests for various usage scenarios
Copilot 1d80375
chore: fixes is component information while walking media types
baywet c574203
fix: content property for header is not getting deserialized v3/3.1/3.2
baywet c4238b6
feat: implements media types references resolution
baywet c7d7753
chore: do not serialize media type components in version prior to 3.2
baywet a10eec7
chore: updates comment
baywet de83a99
Merge branch 'feat/oai-3-2-support' into copilot/fix-1e80ce48-c500-40…
baywet 86f4e83
chore: avoid serializing media types components for anything bellow v…
baywet 7ebed6d
chore: refreshes benchmarks
baywet 91f51bb
test: adds unit tests for header content property deserialization
baywet 1fc5629
Merge branch 'feat/oai-3-2-support' into copilot/fix-1e80ce48-c500-40…
baywet 78458e8
test: adds serialization tests for 32 media type reference serialization
baywet 6c5f86f
test: fixes media type inlining behaviour based on settings
baywet 49f3921
feat: implements inlining of referenced media types when serializing …
baywet 13e2ee9
chore: updates public api export
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/Microsoft.OpenApi/Models/Interfaces/IOpenApiMediaType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public interface IOpenApiMediaType : IOpenApiReadOnlyExtensible, IShallowCopyable<IOpenApiMediaType>, IOpenApiReferenceable | ||
{ | ||
/// <summary> | ||
/// The schema defining the type used for the request body. | ||
/// </summary> | ||
public IOpenApiSchema? Schema { get; } | ||
|
||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public IOpenApiSchema? ItemSchema { get; } | ||
|
||
/// <summary> | ||
/// Example of the media type. | ||
/// The example object SHOULD be in the correct format as specified by the media type. | ||
/// </summary> | ||
public JsonNode? Example { get; } | ||
|
||
/// <summary> | ||
/// Examples of the media type. | ||
/// Each example object SHOULD match the media type and specified schema if present. | ||
/// </summary> | ||
public IDictionary<string, IOpenApiExample>? Examples { get; } | ||
|
||
/// <summary> | ||
/// 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. | ||
/// </summary> | ||
public IDictionary<string, OpenApiEncoding>? Encoding { get; } | ||
|
||
/// <summary> | ||
/// An encoding object for items in an array schema. | ||
/// Only applies when the schema is of type array. | ||
/// </summary> | ||
public OpenApiEncoding? ItemEncoding { get; } | ||
|
||
/// <summary> | ||
/// An array of encoding objects for prefixItems in an array schema. | ||
/// Each element corresponds to a prefixItem in the schema. | ||
/// </summary> | ||
public IList<OpenApiEncoding>? PrefixEncoding { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/Microsoft.OpenApi/Models/References/OpenApiMediaTypeReference.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Media Type Object Reference. | ||
/// </summary> | ||
public class OpenApiMediaTypeReference : BaseOpenApiReferenceHolder<OpenApiMediaType, IOpenApiMediaType, BaseOpenApiReference>, IOpenApiMediaType | ||
{ | ||
/// <summary> | ||
/// Constructor initializing the reference object. | ||
/// </summary> | ||
/// <param name="referenceId">The reference Id.</param> | ||
/// <param name="hostDocument">The host OpenAPI document.</param> | ||
/// <param name="externalResource">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 | ||
/// </param> | ||
public OpenApiMediaTypeReference(string referenceId, OpenApiDocument? hostDocument = null, string? externalResource = null) : base(referenceId, hostDocument, ReferenceType.MediaType, externalResource) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Copy constructor | ||
/// </summary> | ||
/// <param name="mediaTypeReference">The media type reference to copy</param> | ||
private OpenApiMediaTypeReference(OpenApiMediaTypeReference mediaTypeReference) : base(mediaTypeReference) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IOpenApiSchema? Schema { get => Target?.Schema; } | ||
|
||
/// <inheritdoc/> | ||
public IOpenApiSchema? ItemSchema { get => Target?.ItemSchema; } | ||
|
||
/// <inheritdoc/> | ||
public JsonNode? Example { get => Target?.Example; } | ||
|
||
/// <inheritdoc/> | ||
public IDictionary<string, IOpenApiExample>? Examples { get => Target?.Examples; } | ||
|
||
/// <inheritdoc/> | ||
public IDictionary<string, OpenApiEncoding>? Encoding { get => Target?.Encoding; } | ||
|
||
/// <inheritdoc/> | ||
public OpenApiEncoding? ItemEncoding { get => Target?.ItemEncoding; } | ||
|
||
/// <inheritdoc/> | ||
public IList<OpenApiEncoding>? PrefixEncoding { get => Target?.PrefixEncoding; } | ||
|
||
/// <inheritdoc/> | ||
public IDictionary<string, IOpenApiExtension>? Extensions { get => Target?.Extensions; } | ||
|
||
/// <inheritdoc/> | ||
public override IOpenApiMediaType CopyReferenceAsTargetElementWithOverrides(IOpenApiMediaType source) | ||
{ | ||
return source is OpenApiMediaType ? new OpenApiMediaType(this) : source; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IOpenApiMediaType CreateShallowCopy() | ||
{ | ||
return new OpenApiMediaTypeReference(this); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference) | ||
{ | ||
return new BaseOpenApiReference(sourceReference); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.