Skip to content

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

Closed
roman-kms wants to merge 1 commit into
PawelGerr:masterfrom
roman-kms:fix/swashbuckle-options-recursion
Closed

roman-kms wants to merge 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.
@roman-kms roman-kms closed this Oct 19, 2026
@roman-kms
roman-kms deleted the fix/swashbuckle-options-recursion branch October 19, 2026 11:53
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.

1 participant