Skip to content

Commit de72b1d

Browse files
Copilotbaywet
andauthored
test(reader): add nullable-before-type tests for V3.0 and V3.2
Agent-Logs-Url: https://github.com/microsoft/OpenAPI.NET/sessions/6de5cea9-ff8f-4a95-804d-493007f279f3 Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
1 parent 94b606d commit de72b1d

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSchemaTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ public void ParseSchemaWithTypeArrayWorks()
131131
Assert.Equivalent(expected, actual);
132132
}
133133

134+
[Theory]
135+
[InlineData(@"{ ""nullable"": true, ""type"": ""string"" }")]
136+
[InlineData(@"{ ""type"": ""string"", ""nullable"": true }")]
137+
public void ParseSchemaWithNullableBeforeOrAfterTypePreservesNullFlag(string schemaJson)
138+
{
139+
// Act
140+
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(schemaJson, OpenApiSpecVersion.OpenApi3_2, new(), out _, "json", SettingsFixture.ReaderSettings);
141+
142+
// Assert
143+
Assert.Equal(JsonSchemaType.String | JsonSchemaType.Null, schema.Type);
144+
}
145+
134146
[Fact]
135147
public void TestSchemaCopyConstructorWithTypeArrayWorks()
136148
{

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ public void ParsePathFragmentShouldSucceed()
133133
}, openApiAny);
134134
}
135135

136+
[Theory]
137+
[InlineData(@"{ ""nullable"": true, ""type"": ""string"" }")]
138+
[InlineData(@"{ ""type"": ""string"", ""nullable"": true }")]
139+
public void ParseSchemaWithNullableBeforeOrAfterTypePreservesNullFlag(string schemaJson)
140+
{
141+
// Act
142+
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(schemaJson, OpenApiSpecVersion.OpenApi3_0, new(), out _, "json", SettingsFixture.ReaderSettings);
143+
144+
// Assert
145+
Assert.Equal(JsonSchemaType.String | JsonSchemaType.Null, schema.Type);
146+
}
147+
136148
[Fact]
137149
public void ParseDictionarySchemaShouldSucceed()
138150
{

0 commit comments

Comments
 (0)