Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 1, 2025

Summary

This PR implements support for the itemEncoding and prefixEncoding fields in OpenApiMediaType as defined in the OpenAPI 3.2.0 specification.

Changes

New Properties

  • itemEncoding (OpenApiEncoding?): An encoding object for items in an array schema
  • prefixEncoding (IList<OpenApiEncoding>?): An array of encoding objects for prefixItems in an array schema

Version-Specific Serialization

Following the pattern established for other 3.2.0 fields:

OpenAPI 3.2.0+: Fields are serialized as native properties

{
  "itemEncoding": {
    "contentType": "text/plain"
  },
  "prefixEncoding": [
    {
      "contentType": "application/json"
    }
  ]
}

OpenAPI 3.1 and earlier: Fields are serialized as x-oai- prefixed extensions

{
  "x-oai-itemEncoding": {
    "contentType": "text/plain"
  },
  "x-oai-prefixEncoding": [
    {
      "contentType": "application/json"
    }
  ]
}

Implementation Details

  1. Constants: Added ItemEncoding and PrefixEncoding to OpenApiConstants
  2. Model: Added properties to OpenApiMediaType with proper copy constructor support
  3. Serialization: Updated SerializeInternal to handle version-specific output
  4. Deserialization: Updated all version deserializers (v3.0, v3.1, v3.2) to read the fields
  5. Tests: Added comprehensive serialization and deserialization tests for both v3.2 (native) and v3.1/v3.0 (extension) formats
  6. Public API: Updated PublicApi.approved.txt to reflect the new public surface
  7. Bug Fix: Fixed typo in OpenApiEncodingDeserializer where allowedReserved was misspelled (should be allowReserved)

Testing

All existing tests pass, plus 10 new tests covering:

  • itemEncoding serialization in v3.2 (native)
  • itemEncoding serialization in v3.1 (extension)
  • prefixEncoding serialization in v3.2 (native)
  • prefixEncoding serialization in v3.1 (extension)
  • itemEncoding deserialization in v3.2 (native)
  • itemEncoding deserialization in v3.1 (x-oai- extension)
  • itemEncoding deserialization in v3.0 (x-oai- extension)
  • prefixEncoding deserialization in v3.2 (native)
  • prefixEncoding deserialization in v3.1 (x-oai- extension)
  • prefixEncoding deserialization in v3.0 (x-oai- extension)

Fixes

Resolves the issue by providing full support for these OAI 3.2.0 media type fields with backward compatibility for earlier versions.

Warning

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

  • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.Tests.deps.json /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/testhost.dll --port 33553 --endpoint 127.0.0.1:033553 --role client --parentprocessid 6047 --telemetryoptedin false (dns block)
  • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.Tests.deps.json /home/REDACTED/work/OpenAPI.NET/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/bin/Debug/net8.0/testhost.dll --port 38053 --endpoint 127.0.0.1:038053 --role client --parentprocessid 11070 --telemetryoptedin false (dns block)

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

Fixes #10

Original prompt

This section details on the original issue you should resolve

<issue_title>add support for the mediaType itemEncoding and prefixEncoding fields</issue_title>
<issue_description>OAI 3.2.0 defines two new fields for media type.

  • itemEncoding (OpenAPIEncoding?)
  • prefixEncoding (OpenAPIEncoding[]?)

In both cases the fields need to be added to the model and serialization/deserialization should be updated.

When serializing to OAI 3.1.0 or lower, those properties should be prefixed with x-oai- so they are stored as extensions</issue_description>

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

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

Fixes #10

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

@Copilot Copilot AI changed the title [WIP] add support for the mediaType itemEncoding and prefixEncoding fields Add support for itemEncoding and prefixEncoding fields in OpenApiMediaType Oct 1, 2025
@Copilot Copilot AI requested a review from baywet October 1, 2025 18:14
Copilot finished work on behalf of baywet October 1, 2025 18:14
@baywet
Copy link

baywet commented Oct 2, 2025

@copilot add unit tests for deserialization

- Added 6 new sample YAML files for testing deserialization
- Added 6 new test methods across V3.0, V3.1, and V3.2 deserializers
- Fixed typo in OpenApiEncodingDeserializer: "allowedReserved" -> "allowReserved"
- Tests verify proper deserialization of itemEncoding and prefixEncoding in native (v3.2) and x-oai- prefixed (v3.0, v3.1) formats

Co-authored-by: baywet <[email protected]>
Copy link
Author

Copilot AI commented Oct 2, 2025

@copilot add unit tests for deserialization

Added comprehensive deserialization tests for itemEncoding and prefixEncoding fields in commit b4eec89. The tests cover:

  • V3.2: Native itemEncoding and prefixEncoding field deserialization
  • V3.1 & V3.0: x-oai-itemEncoding and x-oai-prefixEncoding extension deserialization

Also fixed a bug in the OpenApiEncodingDeserializer where allowedReserved was misspelled (should be allowReserved), which was preventing proper deserialization of the allowReserved field.

Copilot finished work on behalf of baywet October 2, 2025 16:30
@baywet baywet marked this pull request as ready for review October 2, 2025 16:53
@baywet baywet enabled auto-merge October 2, 2025 16:53
@baywet baywet merged commit c1a3afb into feat/oai-3-2-support Oct 2, 2025
6 checks passed
@baywet baywet deleted the copilot/fix-ea45d0db-41a9-4eb8-ab64-a899005cb84b branch October 2, 2025 18:06
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 the mediaType itemEncoding and prefixEncoding fields

3 participants