Skip to content

Commit 3eb4f02

Browse files
committed
Add test to validate
1 parent bf9a481 commit 3eb4f02

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,5 +1356,94 @@ public void CopyConstructorForAdvancedDocumentWorks()
13561356
Assert.Equal(2, doc.Paths.Count);
13571357
Assert.NotNull(doc.Components);
13581358
}
1359+
1360+
[Fact]
1361+
public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue()
1362+
{
1363+
// Arrange
1364+
var expected = @"openapi: 3.0.1
1365+
info:
1366+
title: magic style
1367+
version: 1.0.0
1368+
paths:
1369+
/foo:
1370+
get:
1371+
parameters:
1372+
- name: id
1373+
in: query
1374+
schema:
1375+
type: object
1376+
additionalProperties:
1377+
type: integer
1378+
responses:
1379+
'200':
1380+
description: foo
1381+
content:
1382+
text/plain:
1383+
schema:
1384+
type: string";
1385+
1386+
var doc = new OpenApiDocument
1387+
{
1388+
Info = new OpenApiInfo
1389+
{
1390+
Title = "magic style",
1391+
Version = "1.0.0"
1392+
},
1393+
Paths = new OpenApiPaths
1394+
{
1395+
["/foo"] = new OpenApiPathItem
1396+
{
1397+
Operations = new Dictionary<OperationType, OpenApiOperation>
1398+
{
1399+
[OperationType.Get] = new OpenApiOperation
1400+
{
1401+
Parameters = new List<OpenApiParameter>
1402+
{
1403+
new OpenApiParameter
1404+
{
1405+
Name = "id",
1406+
In = ParameterLocation.Query,
1407+
Schema = new OpenApiSchema
1408+
{
1409+
Type = "object",
1410+
AdditionalProperties = new OpenApiSchema
1411+
{
1412+
Type = "integer"
1413+
}
1414+
}
1415+
}
1416+
},
1417+
Responses = new OpenApiResponses
1418+
{
1419+
["200"] = new OpenApiResponse
1420+
{
1421+
Description = "foo",
1422+
Content = new Dictionary<string, OpenApiMediaType>
1423+
{
1424+
["text/plain"] = new OpenApiMediaType
1425+
{
1426+
Schema = new OpenApiSchema
1427+
{
1428+
Type = "string"
1429+
}
1430+
}
1431+
}
1432+
}
1433+
}
1434+
}
1435+
}
1436+
}
1437+
}
1438+
};
1439+
1440+
// Act
1441+
var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
1442+
1443+
// Assert
1444+
actual = actual.MakeLineBreaksEnvironmentNeutral();
1445+
expected = expected.MakeLineBreaksEnvironmentNeutral();
1446+
actual.Should().Be(expected);
1447+
}
13591448
}
13601449
}

0 commit comments

Comments
 (0)