Skip to content

feat: add JsonConverter for OpenApiSchema System.Text.Json serialization - #2915

Merged
Vincent Biret (baywet) merged 8 commits into
microsoft:mainfrom
Mahdigln:feature/openapi-schema-json-converter
Jul 2, 2026
Merged

feat: add JsonConverter for OpenApiSchema System.Text.Json serialization#2915
Vincent Biret (baywet) merged 8 commits into
microsoft:mainfrom
Mahdigln:feature/openapi-schema-json-converter

Conversation

@Mahdigln

@MahdiglnMahdigln commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

Adds OpenApiSchemaJsonConverter, a System.Text.Json.JsonConverter<OpenApiSchema> that produces clean OpenAPI wire format output instead of the default verbose reflection-based serialization.

Type of Change

  • New feature (non-breaking change which adds functionality)

Related Issue(s)

Closes#2299

Changes Made

  • Added OpenApiSchemaJsonConverter in src/Microsoft.OpenApi/Converters/
  • Supports all OpenAPI versions: 2.0, 3.0, 3.1 (default), 3.2
  • Added Read (deserialization) support in addition to Write (serialization)
  • Updated PublicAPI.Unshipped.txt with new public API surface

Testing

  • Unit tests added/updated
  • All existing tests pass

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

Additional Notes

Usage example:

varoptions=newJsonSerializerOptions();options.Converters.Add(newOpenApiSchemaJsonConverter());// Serializevarjson=JsonSerializer.Serialize(schema,options);// Deserializevarschema=JsonSerializer.Deserialize<OpenApiSchema>(json,options);// Target a specific OpenAPI versionoptions.Converters.Add(newOpenApiSchemaJsonConverter(OpenApiSpecVersion.OpenApi3_0));

@Mahdigln
Mahdigln requested a review from a team as a code ownerJune 29, 2026 10:11

@baywetVincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Let's a couple of comments to help get this merged

Comment threadtest/Microsoft.OpenApi.Tests/Converters/OpenApiSchemaJsonConverterTests.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated
Comment threadsrc/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs Outdated

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces first-class System.Text.Json (de)serialization support for OpenApiSchema by adding a dedicated JsonConverter<OpenApiSchema> that emits/consumes OpenAPI wire-format JSON instead of default reflection-based output, addressing the need described in #2299.

Changes:

  • Added OpenApiSchemaJsonConverter with version-targeted serialization (defaulting to OpenAPI 3.2) and deserialization support.
  • Added unit tests validating basic serialize/deserialize and version-specific behavior.
  • Updated public API baselines to include the new converter; also includes an encoding-only change to global.json.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

FileDescription
src/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.csNew converter implementation for OpenApiSchema using OpenAPI wire-format I/O.
test/Microsoft.OpenApi.Tests/Converters/OpenApiSchemaJsonConverterTests.csNew unit tests covering basic serialization/deserialization scenarios.
src/Microsoft.OpenApi/PublicAPI.Unshipped.txtDeclares the newly added public converter API surface.
global.jsonIntroduces a UTF-8 BOM at file start (encoding-only change).

Comment threadglobal.json Outdated
Comment threadtest/Microsoft.OpenApi.Tests/Converters/OpenApiSchemaJsonConverterTests.cs Outdated

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment threadglobal.json Outdated
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>

@baywetVincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes!

@baywet
Vincent Biret (baywet) enabled auto-merge (squash) July 2, 2026 15:04
This was referenced Aug 8, 2026
Sign up for freeto 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.

OpenApiSchema System.Text.Json (De)Serialization

4 participants

@Mahdigln@peombwa@baywet