Fix missing OpenAPI 3.1 $ref properties#3859
Conversation
Fix missing properties on OpenAPI 3.1 schema references (`default`, `deprecated`). Resolves #3858.
There was a problem hiding this comment.
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
SchemaGeneratorto emitdefault/deprecatedon OpenAPI 3.1$refschemas (when not usingallOfwrapping). - 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.
src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/SchemaGenerator.cs
Show resolved
Hide resolved
Address review comment and add missing code to handle `[DefaultValue]` for schema references on parameters.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Refactor to halve the number of calls to `Type.GetGenericTypeDefinition()` in the worst case.
Updated [swashbuckle.aspnetcore.cli](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) from 10.1.5 to 10.1.7. <details> <summary>Release notes</summary> _Sourced from [swashbuckle.aspnetcore.cli's releases](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases)._ ## 10.1.7 ## What's Changed * Support custom data type for DataTypeAttribute by @tayfunyuksel in domaindrivendev/Swashbuckle.AspNetCore#3868 ## New Contributors * @tayfunyuksel made their first contribution in domaindrivendev/Swashbuckle.AspNetCore#3868 **Full Changelog**: domaindrivendev/Swashbuckle.AspNetCore@v10.1.6...v10.1.7 ## 10.1.6 ## What's Changed * Fix handling of duplicate enum values for dictionaries by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3839 * Log exception when app fails to start in CLI by @ODukhno in domaindrivendev/Swashbuckle.AspNetCore#3853 * Fix missing OpenAPI 3.1 $ref properties by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3859 * Add description for OpenAPI schema references by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3860 ## New Contributors * @ODukhno made their first contribution in domaindrivendev/Swashbuckle.AspNetCore#3853 **Full Changelog**: domaindrivendev/Swashbuckle.AspNetCore@v10.1.5...v10.1.6 Commits viewable in [compare view](domaindrivendev/Swashbuckle.AspNetCore@v10.1.5...v10.1.7). </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) from 10.1.5 to 10.1.7. <details> <summary>Release notes</summary> _Sourced from [Swashbuckle.AspNetCore's releases](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases)._ ## 10.1.7 ## What's Changed * Support custom data type for DataTypeAttribute by @tayfunyuksel in domaindrivendev/Swashbuckle.AspNetCore#3868 ## New Contributors * @tayfunyuksel made their first contribution in domaindrivendev/Swashbuckle.AspNetCore#3868 **Full Changelog**: domaindrivendev/Swashbuckle.AspNetCore@v10.1.6...v10.1.7 ## 10.1.6 ## What's Changed * Fix handling of duplicate enum values for dictionaries by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3839 * Log exception when app fails to start in CLI by @ODukhno in domaindrivendev/Swashbuckle.AspNetCore#3853 * Fix missing OpenAPI 3.1 $ref properties by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3859 * Add description for OpenAPI schema references by @martincostello in domaindrivendev/Swashbuckle.AspNetCore#3860 ## New Contributors * @ODukhno made their first contribution in domaindrivendev/Swashbuckle.AspNetCore#3853 **Full Changelog**: domaindrivendev/Swashbuckle.AspNetCore@v10.1.5...v10.1.6 Commits viewable in [compare view](domaindrivendev/Swashbuckle.AspNetCore@v10.1.5...v10.1.7). </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Fix missing properties on OpenAPI 3.1 schema references (
default,deprecated).Resolves #3858.