Skip to content

Describe System.Text.Json DOM types as free-form JSON in the OpenAPI document - #628

Merged
ipjohnson merged 2 commits into
mainfrom
agent/627-the-openapi-document-describes-jsonnode
Oct 21, 2026
Merged

ipjohnson merged 2 commits into
mainfrom
agent/627-the-openapi-document-describes-jsonnode

Conversation

@ipjohnson

@ipjohnson ipjohnson commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #627.

What changed

JsonSchemaWriter now writes JsonElement, JsonNode and JsonValue as {}, JsonObject as {"type":"object"} and JsonArray as {"type":"array","items":{}}. The types are matched by their System.Text.Json / System.Text.Json.Nodes namespace, so an application's own JsonNode is still reflected. ObjectRef skips indexers, so no schema has a this[] property. A nullable JsonObject or JsonArray gets null added to its type, which lowers to nullable: true at 3.0.0, and a nullable {} stays {}.

For the Refit criterion, scripts/verify-templates.sh copies scripts/probes/JsonDomController.cs into each code-first Refit row that uses the JSON serializer. It then builds the client project and checks that the DOM operations are in the generated client. This runs after the row's tests, because the scaffold's DocumentStatusTests fails on any operation it does not probe. The probe is removed afterwards.

The separate commit bumps MessagePack from 3.1.8 to 3.1.9 for GHSA-qhrr-8q5h-9q3h, which was published on 2026-10-15. Without it, NU1902 fails the Release CI build at restore, on main as well. The template's pin and the two doc pages that cite the version move with it.

How it was tested

JsonDomDocumentTests covers each of the five types as a property, a request body and a response. It runs the generated document through the export's lowering and YAML writer at 3.2.0, 3.1.0 and 3.0.0, and reads the YAML back with Microsoft.OpenApi to check it matches the JSON. It also checks that no component is written for the five types, JsonNodeOptions or JsonValueKind, that a user type named JsonNode is still reflected, and that an indexer is not a property. The suite fails 25 tests against the old writer.

scripts/verify-templates.sh kestrel:code:response:refit kestrel:code:throws:refit:nunit reports that the Refit client compiles over the DOM types on both rows. The overall run still fails on the Azure blob-trigger function row, because no storage emulator is listening on 127.0.0.1:10000 on this machine.

dotnet build Hardened.slnx --configuration Release -p:ContinuousIntegrationBuild=true has 0 warnings and 0 errors, dotnet test Hardened.slnx passes across all 80 test assemblies, and dotnet csharpier check . is clean. No golden fixture or tracked openapi/*.json changed.

🤖 Generated with Claude Code


Agent Driver: session 2d7049bb, Task 2052ce41 (Describe System.Text.Json DOM types as free-form JSON in the OpenAPI document), item describe-system-text-json-dom-types-as-f. Open on your network

Ian Johnson and others added 2 commits October 21, 2026 08:25
GHSA-qhrr-8q5h-9q3h covers 3.0.0 through 3.1.8, and NU1902 is an error under
ContinuousIntegrationBuild, so the Release build failed at restore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Driver-Session: 2d7049bb-6fd8-4372-8d0f-661c0a5b9754
…document

JsonElement, JsonNode and JsonValue are written as {}, JsonObject as
{"type":"object"} and JsonArray as {"type":"array","items":{}}, matched by their
System.Text.Json and System.Text.Json.Nodes namespaces. The member walk skips
indexers, so no schema has a this[] property. verify-templates.sh builds the
Refit client of each code-first JSON Refit row over a probe handler that uses
the five types.

Closes #627

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Agent-Driver-Session: 2d7049bb-6fd8-4372-8d0f-661c0a5b9754
@ipjohnson
ipjohnson merged commit 5a6fcd4 into main Oct 21, 2026
6 checks passed
@ipjohnson ipjohnson mentioned this pull request Oct 21, 2026
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.

The OpenAPI document describes JsonNode, JsonObject and JsonElement by their CLR members

1 participant