Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MvcOptions from SchemaGenerator #3242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

EvgeniyZ
Copy link
Contributor

The issue or feature being addressed

Fixes #3203

Details on the issue fix or feature implementation

remove any usages of MvcOptions in 'SchemaGenerator'. It should not be a breaking change since bool expression is 'true' by definition if 'SuppressImplicitRequiredAttributeForNonNullableReferenceTypes=false'

remove any usages of MvcOptions in 'SchemaGenerator'. It should not be a breaking change
since bool expression is 'true' by definition if 'SuppressImplicitRequiredAttributeForNonNullableReferenceTypes=false'
@@ -202,7 +202,6 @@ Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext.Type.get -> System.Type
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(System.Type modelType, Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository schemaRepository, System.Reflection.MemberInfo memberInfo = null, System.Reflection.ParameterInfo parameterInfo = null, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterRouteInfo routeInfo = null) -> Microsoft.OpenApi.Models.OpenApiSchema
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.SchemaGenerator(Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions generatorOptions, Swashbuckle.AspNetCore.SwaggerGen.ISerializerDataContractResolver serializerDataContractResolver) -> void
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.SchemaGenerator(Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions generatorOptions, Swashbuckle.AspNetCore.SwaggerGen.ISerializerDataContractResolver serializerDataContractResolver, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcOptions> mvcOptions) -> void
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that I'm breaking backward compatibility by removing this ctor since SchemaGenerator is a public class, but imho it will be misleading to accept 'MvcOptions' ctor parameter and not use it at all...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it is - the better approach would be to mark it as obsolete. We could then remove it in some future major version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, applied suggestion

@@ -984,29 +984,6 @@ public void GenerateSchema_SupportsOption_NonNullableReferenceTypesAsRequired_Re
Assert.Equal(required, propertyIsRequired);
}

[Theory]
[InlineData(typeof(TypeWithNullableContextAnnotated), nameof(TypeWithNullableContextAnnotated.SubTypeWithOneNonNullableContent), nameof(TypeWithNullableContextAnnotated.NonNullableString), false)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the test entirely since these InlineData test inputs are already present in tests above

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the tests to verify that the obsolete constructor behaves as expected (i.e. ignoring the MvcOptions value). Marking the test as obsolete would remove any warnings about obsolete usage, and then we'd delete those tests when the constructor is removed at a future date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you OK if I revert tests in this file only and keep others cleaned up?

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.66%. Comparing base (2826dd9) to head (1d65d2e).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3242      +/-   ##
==========================================
+ Coverage   83.62%   83.66%   +0.03%     
==========================================
  Files          76       76              
  Lines        3182     3177       -5     
  Branches      538      538              
==========================================
- Hits         2661     2658       -3     
+ Misses        521      519       -2     
Flag Coverage Δ
Linux 83.66% <100.00%> (+0.03%) ⬆️
Windows 83.66% <100.00%> (+0.03%) ⬆️
macOS 83.66% <100.00%> (+0.03%) ⬆️

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.

@EvgeniyZ EvgeniyZ changed the title fix for #3203 Remove MvcOptions from SchemaGenerator Jan 30, 2025
@@ -4,6 +4,7 @@
using System.Reflection;
using System.Xml.XPath;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this addition for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, removed

@@ -202,7 +202,6 @@ Swashbuckle.AspNetCore.SwaggerGen.SchemaFilterContext.Type.get -> System.Type
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(System.Type modelType, Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository schemaRepository, System.Reflection.MemberInfo memberInfo = null, System.Reflection.ParameterInfo parameterInfo = null, Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterRouteInfo routeInfo = null) -> Microsoft.OpenApi.Models.OpenApiSchema
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.SchemaGenerator(Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions generatorOptions, Swashbuckle.AspNetCore.SwaggerGen.ISerializerDataContractResolver serializerDataContractResolver) -> void
Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.SchemaGenerator(Swashbuckle.AspNetCore.SwaggerGen.SchemaGeneratorOptions generatorOptions, Swashbuckle.AspNetCore.SwaggerGen.ISerializerDataContractResolver serializerDataContractResolver, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Mvc.MvcOptions> mvcOptions) -> void
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it is - the better approach would be to mark it as obsolete. We could then remove it in some future major version.

@@ -984,29 +984,6 @@ public void GenerateSchema_SupportsOption_NonNullableReferenceTypesAsRequired_Re
Assert.Equal(required, propertyIsRequired);
}

[Theory]
[InlineData(typeof(TypeWithNullableContextAnnotated), nameof(TypeWithNullableContextAnnotated.SubTypeWithOneNonNullableContent), nameof(TypeWithNullableContextAnnotated.NonNullableString), false)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the tests to verify that the obsolete constructor behaves as expected (i.e. ignoring the MvcOptions value). Marking the test as obsolete would remove any warnings about obsolete usage, and then we'd delete those tests when the constructor is removed at a future date.


namespace Swashbuckle.AspNetCore.SwaggerGen
{
public class SchemaGenerator : ISchemaGenerator
{
private readonly SchemaGeneratorOptions _generatorOptions;
private readonly ISerializerDataContractResolver _serializerDataContractResolver;
private readonly IOptions<MvcOptions> _mvcOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the field and usage of the constructor argument, but we need to keep the signature the same but mark it as obsolete instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied suggestion

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.

NonNullableReferenceTypesAsRequired should not consider MvcOptions
3 participants