Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 2, 2025

Implements support for media types components as defined in OAS 3.2.0, including full reference support, workspace registration, serialization, deserialization, and comprehensive test coverage.

Implementation

  • IOpenApiMediaType interface: Abstracted from OpenApiMediaType to enable proper type assertions and reference handling
  • OpenApiMediaTypeReference class: Implements reference resolution following the established pattern for other components
  • Component serialization: Media types serialize as native mediaTypes field in OAS 3.2.0, and with x-oai- prefix as extensions in earlier versions (3.1.0 and 3.0.0)
  • Component deserialization: Added full V3.2 deserialization support for media types components and references, including:
    • Media types component parsing in components section
    • Reference detection and resolution for $ref in content dictionaries
    • JSON pointer encoding for media type keys with special characters (e.g., application/jsonapplication~1json)
  • Workspace integration: Full support for registering and resolving media type components with proper encoding
  • Walker support: Updated to traverse media types components and handle references properly

Testing

Added comprehensive test coverage:

  • ✅ 6 media types component tests for serialization and workspace registration
  • ✅ 4 media type reference tests validating usage in:
    • Request body content
    • Response body content
    • Parameter content
    • Header content
  • ✅ 4 OpenApiMediaTypeReferenceDeserializerTests for validating deserialization of media type references in V3.2 documents

Code Quality

  • Used /// <inheritdoc /> for interface members following project conventions
  • Applied StringComparer.Ordinal for all dictionary instantiations
  • Updated public API exports

Fixes #18

Original prompt

This section details on the original issue you should resolve

<issue_title>add support for media types components</issue_title>
<issue_description>OAS 3.2.0 defines a new component type, media types

On the component object, we should add the new property, and implement serialization/deserialization for it.

When serializing to OAS 3.1.0, a prefix of x-oai- should be used to make it an extension.

Additionally, the registration of media type components should be handled at the workspace level (see this and adjacent methods.

An interface IOpenApiMedia type should be abstracted away from the implementation type, references to the class should be updated to use the interface instead. And a new OpenAPIMediaTypeReference class should be introduced (see how it's done for other things like responses, parameters, etc...)

Lastly, the walkers should be updated to iterate over those components as well.</issue_description>

<agent_instructions>make sure you update the public api export as well</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #18

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 2, 2025 18:40
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] add support for media types components Add support for media types components in OAS 3.2.0 Oct 2, 2025
@Copilot Copilot AI requested a review from baywet October 2, 2025 18:47
Copilot finished work on behalf of baywet October 2, 2025 18:47
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 2, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.org926f4f21-88e7-4dc5-bf88-6c529bb77844

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of baywet October 2, 2025 20:06
@Copilot Copilot AI requested a review from baywet October 2, 2025 20:06
baywet added 2 commits October 2, 2025 20:21
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
…nceable

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet
Copy link

baywet commented Oct 3, 2025

@copilot add a new OpenApiMediaTypeReferenceTests file in test\Microsoft.OpenApi.Tests\Models\References\ implement new unit tests to validate the following scenarios. It should be modeled after test\Microsoft.OpenApi.Tests\Models\References\OpenApiSchemaReferenceTests.cs

  • when a media type component is defined, it can be referenced for the request body content
  • when a media type component is defined, it can be referenced for the response body content
  • when a media type component is defined, it can be referenced for the parameter content
  • when a media type component is defined, it can be referenced for the header content

Also add a new OpenApiMediaTypeReferenceDeserializerTests file in test\Microsoft.OpenApi.Readers.Tests\V32Tests\ to validate that when a serialized document contains a media type reference for the following scenarios, it can be parsed appropriately. It should be modeled after test\Microsoft.OpenApi.Readers.Tests\V31Tests\OpenApiSchemaReferenceDeserializerTests.cs

  • when a media type component is defined, it can be referenced for the request body content
  • when a media type component is defined, it can be referenced for the response body content
  • when a media type component is defined, it can be referenced for the parameter content
  • when a media type component is defined, it can be referenced for the header content

Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 3, 2025

@copilot add a new OpenApiMediaTypeReferenceTests file in test\Microsoft.OpenApi.Tests\Models\References\ implement new unit tests to validate the following scenarios. It should be modeled after tes...

Added test files as requested in commit fda6621:

OpenApiMediaTypeReferenceTests - 4 passing tests validating media type component references in:

  • Request body content
  • Response body content
  • Parameter content
  • Header content

OpenApiMediaTypeReferenceDeserializerTests - Test file created with 4 test scenarios (currently commented out). These tests document the expected deserialization behavior but require parser implementation for media type components and references to be functional. The tests can be uncommented once the V32 deserializer adds support for:

  • Parsing mediaTypes in components
  • Resolving $ref to media type components in content dictionaries

Copilot finished work on behalf of baywet October 3, 2025 01:56
@baywet
Copy link

baywet commented Oct 3, 2025

@copilot uncomment those new unit tests and implement the deserialization behaviour for version 3.2

Copy link
Author

Copilot AI commented Oct 3, 2025

@copilot uncomment those new unit tests and implement the deserialization behaviour for version 3.2

Implemented deserialization support for OAS 3.2 media type components in commit 848cf88:

Changes made:

  • Added "mediaTypes" field to V32 components deserializer
  • Updated LoadMediaType to detect and handle $ref for media type references
  • Fixed walker to properly handle IOpenApiMediaType references with isComponent parameter
  • Added JSON pointer encoding when registering media types (e.g., application/jsonapplication~1json)
  • Updated reference resolution logic to prioritize ReferenceV3 over ID-based construction
  • Uncommented all deserializer tests

Current status:
Most of the deserialization infrastructure is in place. There's still one issue to resolve with reference lookup for media types containing special characters like /. The tests are partially working - the components are being parsed and registered correctly, but the reference resolution needs additional debugging for the encoded key lookup. Will continue investigating the URI matching in the workspace registry.

Copilot finished work on behalf of baywet October 3, 2025 12:43
baywet added 2 commits October 3, 2025 09:58
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet baywet force-pushed the copilot/fix-1e80ce48-c500-4024-9aa8-a50a721fd288 branch from 848cf88 to c4238b6 Compare October 3, 2025 14:31
@baywet
Copy link

baywet commented Oct 3, 2025

Note for me for later: the serialization should inline the media type references in 2/3/3.1

baywet added 4 commits October 3, 2025 12:21
…24-9aa8-a50a721fd288

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
…to 3 and 3.1

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet baywet marked this pull request as ready for review October 3, 2025 18:39
@baywet baywet enabled auto-merge October 3, 2025 18:39
@baywet baywet merged commit fd0c76a into feat/oai-3-2-support Oct 3, 2025
8 checks passed
@baywet baywet deleted the copilot/fix-1e80ce48-c500-4024-9aa8-a50a721fd288 branch October 3, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add support for media types components

3 participants