diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml
index b9d453d2a..fb99868ee 100644
--- a/.github/workflows/ci-cd.yml
+++ b/.github/workflows/ci-cd.yml
@@ -9,6 +9,10 @@ jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ code-quality: write
+ pull-requests: read
env:
ARTIFACTS_FOLDER: ${{ github.workspace }}/Artifacts
GITHUB_RUN_NUMBER: ${{ github.run_number }}
@@ -27,6 +31,7 @@ jobs:
id: checkout_repo
uses: actions/checkout@v6
with:
+ ref: ${{ github.event.pull_request.head.sha || github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
@@ -40,7 +45,36 @@ jobs:
id: run_unit_tests
shell: pwsh
run: |
- dotnet test Microsoft.OpenApi.slnx -c Release -v n
+ dotnet test Microsoft.OpenApi.slnx -c Release --no-build -v n --collect:"XPlat Code Coverage"
+
+ - name: Install report generator
+ shell: pwsh
+ run: |
+ dotnet tool install --global dotnet-reportgenerator-globaltool
+
+ - name: Generate coverage report
+ shell: pwsh
+ run: |
+ reportgenerator -reports:**/coverage.cobertura.xml -targetdir:./reports/coverage -reporttypes:"Html;MarkdownSummaryGithub;Cobertura"
+
+ - name: Add coverage to job summary
+ shell: bash
+ run: |
+ cat ./reports/coverage/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY"
+
+ - name: Upload coverage report
+ if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') || (github.event_name != 'pull_request' && github.ref_name == github.event.repository.default_branch)
+ uses: actions/upload-code-coverage@v1
+ with:
+ file: ./reports/coverage/Cobertura.xml
+ language: CSharp
+ label: code-coverage/dotnet
+
+ - name: Upload coverage artifact
+ uses: actions/upload-artifact@v7
+ with:
+ name: coverage
+ path: reports/coverage
validate-trimming:
name: Validate Project for Trimming
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index ca3f730c7..6f360c576 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "2.7.5"
+ ".": "2.7.6"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b22097196..9012ace57 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## [2.7.6](https://github.com/microsoft/OpenAPI.NET/compare/v2.7.5...v2.7.6) (2026-05-28)
+
+
+### Bug Fixes
+
+* **reader:** preserve nullable Null flag when type appears after nullable in V3.1/V3.2 deserializers ([288e95a](https://github.com/microsoft/OpenAPI.NET/commit/288e95aa743cb98dc69b44577ae78956f3f1c7c4))
+
## [2.7.5](https://github.com/microsoft/OpenAPI.NET/compare/v2.7.4...v2.7.5) (2026-05-26)
diff --git a/Directory.Build.props b/Directory.Build.props
index f06b5bb92..72c92bace 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.7.5
+ 2.7.6
diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
index 731cf45e5..296626a93 100644
--- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
+++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
@@ -198,21 +198,20 @@ internal static partial class OpenApiV31Deserializer
"type",
(o, n, doc) =>
{
+ // Preserve any Null flag set by a preceding "nullable: true" handler
+ var preserveNull = o.Type.HasValue && o.Type.Value.HasFlag(JsonSchemaType.Null);
if (n is ValueNode)
{
- o.Type = n.GetScalarValue()?.ToJsonSchemaType();
+ var parsedType = n.GetScalarValue()?.ToJsonSchemaType();
+ o.Type = preserveNull ? parsedType | JsonSchemaType.Null : parsedType;
}
else
{
var list = n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc);
- JsonSchemaType combinedType = 0;
- foreach(var type in list)
+ JsonSchemaType combinedType = preserveNull ? JsonSchemaType.Null : 0;
+ foreach(var type in list.Where(static t => t is not null).Select(static t => t!.ToJsonSchemaType()))
{
- if (type is not null)
- {
- var schemaType = type.ToJsonSchemaType();
- combinedType |= schemaType;
- }
+ combinedType |= type;
}
o.Type = combinedType;
}
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
index b65b2d8c3..ec66dcbb9 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs
@@ -132,6 +132,18 @@ public void ParseSchemaWithTypeArrayWorks()
Assert.Equivalent(expected, actual);
}
+ [Theory]
+ [InlineData(@"{ ""nullable"": true, ""type"": ""string"" }")]
+ [InlineData(@"{ ""type"": ""string"", ""nullable"": true }")]
+ public void ParseSchemaWithNullableBeforeOrAfterTypePreservesNullFlag(string schemaJson)
+ {
+ // Act
+ var schema = OpenApiModelFactory.Parse(schemaJson, OpenApiSpecVersion.OpenApi3_1, new(), out _, "json", SettingsFixture.ReaderSettings);
+
+ // Assert
+ Assert.Equal(JsonSchemaType.String | JsonSchemaType.Null, schema.Type);
+ }
+
[Fact]
public void TestSchemaCopyConstructorWithTypeArrayWorks()
{
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
index e16e40594..8241e55ed 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
@@ -133,6 +133,18 @@ public void ParsePathFragmentShouldSucceed()
}, openApiAny);
}
+ [Theory]
+ [InlineData(@"{ ""nullable"": true, ""type"": ""string"" }")]
+ [InlineData(@"{ ""type"": ""string"", ""nullable"": true }")]
+ public void ParseSchemaWithNullableBeforeOrAfterTypePreservesNullFlag(string schemaJson)
+ {
+ // Act
+ var schema = OpenApiModelFactory.Parse(schemaJson, OpenApiSpecVersion.OpenApi3_0, new(), out _, "json", SettingsFixture.ReaderSettings);
+
+ // Assert
+ Assert.Equal(JsonSchemaType.String | JsonSchemaType.Null, schema.Type);
+ }
+
[Fact]
public void ParseDictionarySchemaShouldSucceed()
{