Migrate NSwag core to System.Text.Json (v15) - [WIP]#5355
Open
Migrate NSwag core to System.Text.Json (v15) - [WIP]#5355
Conversation
Phase 0: Add UseLocalNJsonSchemaProjects switch to Directory.Build.props and conditional NJsonSchema project/NuGet references to all 6 projects. Phase 1: Add 5 OpenAPI document serialization snapshot tests using Verify to lock down behavior before and after migration. Phase 2: Migrate all 28 NSwag.Core model files from Newtonsoft attributes to STJ equivalents ([JsonPropertyName], [JsonIgnore], [JsonPropertyOrder]). Rewrite OpenApiPathItemConverter for STJ. Add EnumMemberStringEnumConverter for [EnumMember]-aware enum serialization. Add OpenApiParameterJsonConverter to handle the required bool/array property collision between OpenApiParameter and JsonSchema. Add parameterless JsonConstructor to OpenApiComponents for STJ deserialization support. 58/63 NSwag.Core tests pass (4 remaining failures in reference resolution and external file loading - see docs/plans/findings.md).
- Remove [JsonRequired] from OpenApiOAuthFlow.Scopes (real-world specs have OAuth flows without scopes, Newtonsoft was more lenient) - Update findings.md to reflect 0 remaining failures - Remove temp debug test
- NSwagDocumentBase: Replace JObject/JToken with JsonNode/JsonObject, JsonConvert with JsonSerializer, JsonSerializerSettings with JsonSerializerOptions (CamelCase naming, JsonStringEnumConverter) - 10 command files: mechanical [JsonProperty] → [JsonPropertyName], [JsonIgnore] namespace swap, JsonConvert → JsonSerializer
- Core.Yaml: Replace ExpandoObjectConverter with recursive JsonNode to ExpandoObject conversion for YamlDotNet compatibility - AspNetCore: Replace JsonConvert with JsonSerializer in SwaggerUi settings and JsonExceptionFilterAttribute, rewrite exception serialization without Newtonsoft JsonExceptionConverter
- Remove NJsonSchema.NewtonsoftJson package/project reference - Replace unused Newtonsoft using with System.Text.Json.Serialization - Replace JsonConvert.SerializeObject with JsonSerializer.Serialize
- New NSwag.Generation.NewtonsoftJson project with UseNewtonsoftJson() extension method and NewtonsoftJsonSettingsResolver for ASP.NET Core MvcNewtonsoftJsonOptions detection - Remove Newtonsoft using from AspNetCoreOpenApiDocumentGenerator, deprecate GetJsonSerializerSettings in favor of new package - Remove last Newtonsoft usings from CodeGeneration projects Only NSwag.AspNet.WebApi (legacy) and NSwagStudio (WPF) retain Newtonsoft dependencies. All other NSwag projects are now STJ-only.
…ttings - Enable UseLocalNJsonSchemaProjects=true in Directory.Build.props for development on this branch - Replace NewtonsoftJsonSchemaGeneratorSettings with SystemTextJsonSchemaGeneratorSettings across 26 test files - Update snapshot files to reflect STJ-based schema generation output - Remove orphaned Newtonsoft-only test class and its snapshots - Add JsonElement safety net in CSharpValueGenerator for large specs
…nsoft removal - Fix null reference in NSwagDocumentBase (lines 181, 518) - Cache JsonSerializerOptions as static readonly in NSwagDocumentBase - Add depth limit and try-catch to JsonExceptionFilterAttribute serialization - Remove hard Newtonsoft dependency from NSwagServiceCollectionExtensions (reflection-based) - Fix YAML boolean/number type loss (WithAttemptingUnquotedStringTypeDeserialization) - Migrate YamlDocumentTests from Newtonsoft.Json.Linq to System.Text.Json.Nodes - Add parameter IsRequired round-trip test and YAML round-trip test - Add missing NSwag.Generation.NewtonsoftJson reference to AspNetCore.Tests - Fix QueryParametersTests JToken assertion for STJ - Bump Namotion.Reflection to 3.5.0 - Add review.md and migration.md, remove findings.md
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.
No description provided.