Skip to content

fix: defer Newtonsoft resolver detection in the OpenAPI filters - #27

Merged
PawelGerr merged 1 commit into
PawelGerr:masterfrom
roman-kms:fix/swashbuckle-options-recursion
Oct 19, 2026
Merged

PawelGerr merged 1 commit into
PawelGerr:masterfrom
roman-kms:fix/swashbuckle-options-recursion

Conversation

@roman-kms

Copy link
Copy Markdown
Contributor

With Swashbuckle.AspNetCore 10.3.0, generating the OpenAPI document hangs as soon as AddThinktectureOpenApiFilters is registered (dotnet-getdocument times out at build time).

Cause: ThinktectureSchemaFilter/ThinktectureParameterFilter are created inside the SwaggerGenOptions configuration and resolve ISerializerDataContractResolver in their constructors. Since domaindrivendev/Swashbuckle.AspNetCore#3998 the default resolver is built from SchemaGeneratorOptions, whose ConfigureSchemaGeneratorOptions depends on IOptions<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 reads Mvc.JsonOptions when MVC isn't registered (domaindrivendev/Swashbuckle.AspNetCore#4116), while JsonSerializerOptionsResolver still does.

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.

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.

🟢 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

@PawelGerr
PawelGerr merged commit ff21ee7 into PawelGerr:master Oct 19, 2026
1 check failed
@PawelGerr

Copy link
Copy Markdown
Owner

Thank you :)
10.6.0 has been released.

@roman-kms

Copy link
Copy Markdown
Contributor Author

@PawelGerr thanks for the quick release :)

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.

3 participants