diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8da434115..13d9f224f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.3.5" + ".": "2.3.6" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f9571a492..d3b2d987e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.3.6](https://github.com/microsoft/OpenAPI.NET/compare/v2.3.5...v2.3.6) (2025-10-20) + + +### Bug Fixes + +* a bug where empty collections would not be serialized for default values ([4c4d257](https://github.com/microsoft/OpenAPI.NET/commit/4c4d257c0cf10d1742fae9f3961e4a6242c0ce1d)) + ## [2.3.5](https://github.com/microsoft/OpenAPI.NET/compare/v2.3.4...v2.3.5) (2025-10-14) diff --git a/Directory.Build.props b/Directory.Build.props index 46a5bcbea..6d13b2509 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -12,7 +12,7 @@ https://github.com/Microsoft/OpenAPI.NET © Microsoft Corporation. All rights reserved. OpenAPI .NET - 2.3.5 + 2.3.6 diff --git a/global.json b/global.json index da70a0aea..4c2f00caf 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "8.0.414" + "version": "8.0.415" } } \ No newline at end of file diff --git a/performance/resultsComparer/resultsComparer.csproj b/performance/resultsComparer/resultsComparer.csproj index 82a71aab7..c409872f6 100644 --- a/performance/resultsComparer/resultsComparer.csproj +++ b/performance/resultsComparer/resultsComparer.csproj @@ -8,12 +8,12 @@ - - - - + + + + - + diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 72a6485ea..7e61230e4 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -29,10 +29,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index cfd669367..2303fdedc 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -13,7 +13,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs index f2e4aa5a9..f346dddc4 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs @@ -141,9 +141,9 @@ public static void WriteOptionalObject( { if (value != null) { - if (value is IEnumerable values && !values.GetEnumerator().MoveNext()) + if (value is IEnumerable values && value is not JsonArray && !values.GetEnumerator().MoveNext()) { - return; // Don't render optional empty collections + return; // Don't render optional empty collections except for the Default properties which are JsonArray } writer.WriteRequiredObject(name, value, action); diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index 33656177d..5b5b5fedf 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index 8e19f7370..39befa33f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -19,9 +19,9 @@ - + - + diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs index 72fb153dd..c992f6656 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs @@ -315,6 +315,40 @@ public void CloningSchemaWithExamplesAndEnumsShouldSucceed() Assert.Equivalent(6, clone.Default.GetValue()); } + [Fact] + public void DefaultEmptyCollectionShouldRoundTrip() + { + // Given + var serializedSchema = + """ + { + "type": "array", + "items": { + "type": "string", + "default": [] + } + } + """; + using var textWriter = new StringWriter(); + var writer = new OpenApiJsonWriter(textWriter); + + // When + var schema = OpenApiModelFactory.Parse(serializedSchema, OpenApiSpecVersion.OpenApi3_1, new(), out _, "json", SettingsFixture.ReaderSettings); + + var deserializedArray = Assert.IsType(schema.Items.Default); + Assert.Empty(deserializedArray); + + schema.SerializeAsV31(writer); + var roundTrippedSchema = textWriter.ToString(); + + // Then + var parsedResult = JsonNode.Parse(roundTrippedSchema); + var parsedExpected = JsonNode.Parse(serializedSchema); + Assert.True(JsonNode.DeepEquals(parsedExpected, parsedResult)); + var resultingArray = Assert.IsType(parsedResult["items"]?["default"]); + Assert.Empty(resultingArray); + } + [Fact] public async Task SerializeV31SchemaWithMultipleTypesAsV3Works() { diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 1650bdf75..98b459aa6 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -13,10 +13,10 @@ - - + + - +