Skip to content

[release/11.0-preview7] Add contentEncoding: base64 to JSON schema for byte[], Memory, and ReadOnlyMemory - #131412

Open
Youssef1313 with Copilot wants to merge 1 commit into
release/11.0-preview7from
copilot/backport-pr-130881
Open

[release/11.0-preview7] Add contentEncoding: base64 to JSON schema for byte[], Memory, and ReadOnlyMemory#131412
Youssef1313 with Copilot wants to merge 1 commit into
release/11.0-preview7from
copilot/backport-pr-130881

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

main PR #130881

Description

JsonSchemaExporter was omitting "contentEncoding": "base64" for byte-array types despite STJ serializing them as base64 strings. Per JSON Schema 2020-12 §8.3, contentEncoding must be set when the string payload is encoded.

  • JsonSchema.cs: Added ContentEncodingPropertyName constant and ContentEncoding property; wired into KeywordCount and ToJsonNode
  • ByteArrayConverter, MemoryByteConverter, ReadOnlyMemoryByteConverter: GetSchema() now returns ContentEncoding = "base64"
  • JsonSchemaExporterTests.TestTypes.cs: Updated expected schemas for byte[], Memory<byte>, ReadOnlyMemory<byte>

Before / After:

// byte[] — before
{ "type": ["string", "null"] }
// byte[] — after
{ "type": ["string", "null"], "contentEncoding": "base64" }

// Memory<byte> / ReadOnlyMemory<byte> — after
{ "type": "string", "contentEncoding": "base64" }

Customer Impact

Consumers using JsonSchemaExporter to generate schemas for types with byte[], Memory<byte>, or ReadOnlyMemory<byte> properties get incomplete schemas — validators and tooling that rely on contentEncoding will not correctly identify the base64 encoding constraint.

Regression

No — this is a missing feature, not a regression.

Testing

All 387 JsonSchemaExporter tests pass, including the updated expectations for the three affected types.

Risk

Low. Changes are confined to three converters and the internal JsonSchema class. No behavior change to serialization/deserialization; only affects schema generation output.

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

…yte[], Memory, and ReadOnlyMemory

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 27, 2026 10:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json
See info in area-owners.md if you want to be subscribed.

@Youssef1313
Youssef1313 marked this pull request as ready for review July 27, 2026 12:04
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants