Repository navigation
fix: defer Newtonsoft resolver detection in the OpenAPI filters - #27
Merged
PawelGerr merged 1 commit intoOct 19, 2026
Merged
Conversation
ThinktectureSchemaFilter and ThinktectureParameterFilter are created inside the SwaggerGenOptions configuration of AddThinktectureOpenApiFilters. Their constructors resolved ISerializerDataContractResolver to detect Swashbuckle.AspNetCore.Newtonsoft. Since Swashbuckle 10.3.0 the default resolver is built from SchemaGeneratorOptions, which are configured from SwaggerGenOptions. Resolving it during that configuration re-enters it, so building the OpenAPI document recurses endlessly and hangs (e.g. dotnet-getdocument times out at build time). Detect the resolver lazily on first use instead.
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix breaks the configuration cycle and includes targeted regression coverage; tests were not run.
No open issues 🎉
What changed in this PR
Fixes OpenAPI generation hangs by deferring Newtonsoft resolver detection until the Thinktecture filters run, avoiding recursive options configuration.
Changes:
- Lazily detect the resolver in both filters without changing serializer selection.
- Add a regression test reproducing the Swashbuckle 10.3 dependency chain.
| File | Description |
|---|---|
| test/Thinktecture.Runtime.Extensions.Swashbuckle.Tests.Sources/Swashbuckle/ThinktectureSchemaFilterTests.ObjectFactories.cs | Adds document-generation regression coverage. |
| test/Thinktecture.Runtime.Extensions.Swashbuckle.Tests.Sources/Swashbuckle/ThinktectureSchemaFilterTests.cs | Adds resolver registration reproducing the configuration cycle. |
| src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/ThinktectureSchemaFilter.cs | Defers schema-filter resolver detection. |
| src/Thinktecture.Runtime.Extensions.Swashbuckle/Swashbuckle/Internal/ThinktectureParameterFilter.cs | Defers parameter-filter resolver detection. |
Review effort: Balanced
Owner
|
Thank you :) |
Contributor
Author
|
@PawelGerr thanks for the quick release :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With Swashbuckle.AspNetCore 10.3.0, generating the OpenAPI document hangs as soon as
AddThinktectureOpenApiFiltersis registered (dotnet-getdocumenttimes out at build time).Cause:
ThinktectureSchemaFilter/ThinktectureParameterFilterare created inside theSwaggerGenOptionsconfiguration and resolveISerializerDataContractResolverin their constructors. Since domaindrivendev/Swashbuckle.AspNetCore#3998 the default resolver is built fromSchemaGeneratorOptions, whoseConfigureSchemaGeneratorOptionsdepends onIOptions<SwaggerGenOptions>, so the configuration re-enters itself endlessly.Fix: detect the Newtonsoft resolver lazily on first
Apply. Behavior with Swashbuckle 10.1.0 is unchanged; a regression test mirrors the 10.3 registration.Heads-up, not part of this PR: bumping the tests to 10.3.0 changes two snapshots (
*_with_string_enum_converter_as_body_parameter). Swashbuckle no longer readsMvc.JsonOptionswhen MVC isn't registered (domaindrivendev/Swashbuckle.AspNetCore#4116), whileJsonSerializerOptionsResolverstill does.