Skip to content

Clarify nullable behaviour - #4094

Merged
martincostello merged 1 commit into
masterfrom
gh-3976-follow-up
Aug 3, 2026
Merged

martincostello merged 1 commit into
masterfrom
gh-3976-follow-up

Conversation

@martincostello

@martincostello martincostello commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #3976:

  • Add clarifying comments and tests.
  • Fix asymmetry with handling anyOf and oneOf.

Follow-up to #3976:

- Add clarifying comments.
- Fix asymmetry with handling `anyOf` and `oneOf`.
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.11%. Comparing base (0ca5050) to head (c88a41f).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4094      +/-   ##
==========================================
+ Coverage   95.08%   95.11%   +0.02%     
==========================================
  Files         111      111              
  Lines        4046     4070      +24     
  Branches      820      832      +12     
==========================================
+ Hits         3847     3871      +24     
  Misses        199      199              
Flag Coverage Δ
Linux 95.11% <100.00%> (+0.02%) ⬆️
Windows 95.11% <100.00%> (+0.02%) ⬆️
macOS 95.11% <100.00%> (+0.02%) ⬆️

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.

@martincostello
martincostello marked this pull request as ready for review August 3, 2026 16:58
Copilot AI review requested due to automatic review settings August 3, 2026 16:58

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.

🟡 Human review recommended

It changes core schema nullability behavior across composed-schema shapes and spec-version serialization semantics, which warrants a final human validation pass despite the added tests.

Pull request overview

This PR is a follow-up to #3976 that clarifies and verifies nullability behavior for composed schemas, specifically addressing symmetry between nullable and non-nullable handling when schemas use anyOf, oneOf, or allOf, and ensuring serialization remains sensible across OpenAPI/Swagger versions.

Changes:

  • Add non-nullable “mirror image” behaviors for composed schemas by removing null from anyOf/oneOf members (or clearing the Null flag) when a member is non-nullable.
  • Add targeted unit tests for non-nullable composed-schema scenarios and for dictionary value schemas that intentionally omit type (and nullable) across OpenAPI 3.1/3.0/Swagger 2.0.
  • Add clarifying inline documentation in both SchemaGenerator and AnnotationsSchemaFilter describing where nullability is represented depending on schema shape.
File summaries
File Description
test/Swashbuckle.AspNetCore.TestSupport/Fixtures/JsonSerializerSchemaGeneratorTestTypes.cs Adds non-nullable fixture types used to validate composed-schema nullability behavior.
test/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.cs Adds tests covering non-nullable removal of null from anyOf/oneOf, and serialization expectations for “no type” schemas across spec versions.
test/Swashbuckle.AspNetCore.Annotations.Test/AnnotationsSchemaFilterTests.cs Adds tests verifying SwaggerSchema(Nullable=false) removes null from compositions and refactors the test helper to support multiple declaring types.
src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs Implements non-nullable “mirror” behavior by removing/clearing null within anyOf/oneOf when nullable=false, with explanatory comments.
src/Swashbuckle.AspNetCore.Annotations/AnnotationsSchemaFilter.cs Mirrors the same non-nullable composition handling for annotation-driven nullability, plus clarifying comments.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@martincostello
martincostello merged commit 436e869 into master Aug 3, 2026
22 of 23 checks passed
@martincostello
martincostello deleted the gh-3976-follow-up branch August 3, 2026 17:04
This was referenced Oct 7, 2026
This was referenced Oct 11, 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.

2 participants