Skip to content

Fix missing OpenAPI 3.1 $ref properties#3859

Merged
martincostello merged 4 commits intomasterfrom
gh-3858
Mar 24, 2026
Merged

Fix missing OpenAPI 3.1 $ref properties#3859
martincostello merged 4 commits intomasterfrom
gh-3858

Conversation

@martincostello
Copy link
Collaborator

Fix missing properties on OpenAPI 3.1 schema references (default, deprecated).

Resolves #3858.

Fix missing properties on OpenAPI 3.1 schema references (`default`, `deprecated`).

Resolves #3858.
@martincostello martincostello added this to the v10.1.6 milestone Mar 24, 2026
Copilot AI review requested due to automatic review settings March 24, 2026 15:02
Copy link

Copilot AI left a comment

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 addresses issue #3858 by ensuring OpenAPI 3.1 schemas can retain certain “sibling” properties (default, deprecated) even when the schema is emitted as a $ref, improving fidelity for referenced enums and other referenced schemas.

Changes:

  • Update SchemaGenerator to emit default/deprecated on OpenAPI 3.1 $ref schemas (when not using allOf wrapping).
  • Extend integration test coverage to snapshot OpenAPI 2.0 and 3.1 outputs for the Basic test site.
  • Add/adjust fixtures and unit tests to cover enum default values and deprecated properties.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs Adds default/deprecated support on referenced member schemas without forcing allOf.
test/WebSites/Basic/Controllers/SwaggerAnnotationsController.cs Adds enum default and an obsolete property to exercise $ref + default/deprecated behavior.
test/WebSites/Basic/Controllers/DefaultValuesAttribute.cs Removes unused custom attribute in favor of System.ComponentModel.DefaultValueAttribute.
test/Swashbuckle.AspNetCore.TestSupport/Fixtures/TypeWithDefaultAttributes.cs Adds an enum property with DefaultValue for unit test coverage.
test/Swashbuckle.AspNetCore.TestSupport/Fixtures/TypeWithDefaultAttributeOnEnum.cs Minor formatting update in fixture (no functional change).
test/Swashbuckle.AspNetCore.TestSupport/Fixtures/ComplexType.cs Adds an enum property with DefaultValue and updates usings for schema-generation tests.
test/Swashbuckle.AspNetCore.SwaggerGen.Test/SchemaGenerator/JsonSerializerSchemaGeneratorTests.cs Updates schema assertions and adds enum default test coverage.
test/Swashbuckle.AspNetCore.Newtonsoft.Test/SchemaGenerator/NewtonsoftSchemaGeneratorTests.cs Updates schema assertions to account for the new ComplexType property.
test/Swashbuckle.AspNetCore.IntegrationTests/VerifyTests.cs Adds snapshot coverage for Basic’s 2.0 and 3.1 endpoints and disambiguates snapshot parameters.
test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs Includes the additional Basic endpoints in integration coverage.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/code/GeneratesValidClient_6548ff89f26311aa/Models/Cart.verified.cs Snapshot updated for the newly added model property.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/8_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=v1.verified.txt Snapshot updated for the added model property.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/8_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=2.0.verified.txt New snapshot covering OpenAPI 2.0 output.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/8_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=3.1.verified.txt New snapshot covering OpenAPI 3.1 output (incl. $ref sibling props).
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/9_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=v1.verified.txt Snapshot updated for the added model property.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/9_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=2.0.verified.txt New snapshot covering OpenAPI 2.0 output.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/9_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=3.1.verified.txt New snapshot covering OpenAPI 3.1 output (incl. $ref sibling props).
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/10_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=v1.verified.txt Snapshot updated for the added model property.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/10_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=2.0.verified.txt New snapshot covering OpenAPI 2.0 output.
test/Swashbuckle.AspNetCore.IntegrationTests/snapshots/10_0/VerifyTests.SwaggerEndpoint_ReturnsValidSwaggerJson_startupType=Basic.Startup_swaggerRequestUri=3.1.verified.txt New snapshot covering OpenAPI 3.1 output (incl. $ref sibling props).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ignore duplicative code generation tests.
Address review comment and add missing code to handle `[DefaultValue]` for schema references on parameters.
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.97%. Comparing base (ef008b6) to head (135623b).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3859      +/-   ##
==========================================
+ Coverage   94.95%   94.97%   +0.02%     
==========================================
  Files         111      111              
  Lines        3886     3903      +17     
  Branches      783      789       +6     
==========================================
+ Hits         3690     3707      +17     
  Misses        196      196              
Flag Coverage Δ
Linux 94.97% <100.00%> (+0.02%) ⬆️
Windows 94.97% <100.00%> (+0.02%) ⬆️
macOS 94.97% <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 Sentry.
📢 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.

Refactor to halve the number of calls to `Type.GetGenericTypeDefinition()` in the worst case.
@martincostello martincostello enabled auto-merge (squash) March 24, 2026 16:27
@martincostello martincostello merged commit b2a9a92 into master Mar 24, 2026
14 checks passed
@martincostello martincostello deleted the gh-3858 branch March 24, 2026 16:38
This was referenced Mar 24, 2026
This was referenced Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default values for enum are not written

2 participants