Skip to content

Add regression tests for nullable dynamic properties - #4182

Merged
martincostello merged 1 commit into
domaindrivendev:masterfrom
JulianThoms:test/4181-nullable-untyped-properties
Oct 1, 2026
Merged

martincostello merged 1 commit into
domaindrivendev:masterfrom
JulianThoms:test/4181-nullable-untyped-properties

Conversation

@JulianThoms

Copy link
Copy Markdown
Contributor

Pull Request

The issue or feature being addressed

Fixes #4181.

In v10.2.3, marking a nullable object property as nullable gives its untyped schema a null-only type. Microsoft.OpenApi 2.12.0 serializes that as enum: [null] in OpenAPI 3.0, restricting the property to null and breaking downstream client generation.

The generator fix from #3976 is already on master, but is absent from v10.2.3. This PR adds regression coverage for the direct-property scenario reported in #4181.

Details on the issue fix or feature implementation

  • Cover nullable dynamic properties and array items with System.Text.Json (object, JsonDocument, and JsonElement?) and Newtonsoft.Json (object, JToken, JObject, and JArray), using the existing fixture with nullable reference types disabled and default generator options.
  • Check that serialized object properties and array items have neither type nor enum in Swagger 2.0 and OpenAPI 3.0/3.1, while preserving the array's type and nullability.
  • Reuse the existing schema generation and document serialization helpers.

Validation:

  • dotnet pack --configuration Release: passed with no warnings or errors.
  • dotnet test --configuration Release: 4,033 passed, zero failed or skipped across .NET 8, 9, and 10, including integration and UI tests.
  • The six new System.Text.Json cases also pass with Microsoft.OpenApi 2.12.0 substituted into an isolated test output directory at runtime.
  • Restoring the v10.2.3 SetNullable logic in an isolated build makes five of those six cases fail with Microsoft.OpenApi 2.12.0, including the OpenAPI 3.0 enum assertion. The source was restored after the check.

PR Checklist

  • I have read and followed the Contributing guide.
  • I have added tests for my changes where appropriate.
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR.
  • This PR has content that I did not fully write myself.

Note

This PR's code and description were generated with OpenAI Codex. The contributor review checkbox is left for the human author to complete.

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.19%. Comparing base (341a21d) to head (dc0ce50).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4182   +/-   ##
=======================================
  Coverage   95.19%   95.19%           
=======================================
  Files         111      111           
  Lines        4165     4165           
  Branches      852      852           
=======================================
  Hits         3965     3965           
  Misses        200      200           
Flag Coverage Δ
Linux 95.19% <ø> (ø)
Windows 95.19% <ø> (ø)
macOS 95.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The focused tests accurately cover the reported regression and serializer parity without changing production behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Adds regression coverage ensuring nullable dynamic JSON properties remain untyped across serializers and OpenAPI versions.

Changes:

  • Tests System.Text.Json dynamic properties, array items, and serialization.
  • Adds equivalent Newtonsoft.Json schema-generation coverage.
File Description
JsonSerializerSchemaGeneratorTests.cs Covers nullable dynamic schemas and OpenAPI 2.0/3.0/3.1 output.
NewtonsoftSchemaGeneratorTests.cs Covers nullable Newtonsoft dynamic types and arrays.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@martincostello
martincostello merged commit 21e22b2 into domaindrivendev:master Oct 1, 2026
20 of 21 checks passed
This was referenced Oct 7, 2026
This was referenced Oct 10, 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.

[Bug]: Nullable object property generates enum: [null] in OpenAPI 3.0 output with Microsoft.OpenApi 2.12.0

3 participants