Skip to content

Commit d010384

Browse files
Copilotbaywet
andcommitted
Fix allowReserved typo in V3 and V31 encoding deserializers and add regression tests
Co-authored-by: baywet <[email protected]>
1 parent 649dfe3 commit d010384

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

src/Microsoft.OpenApi/Reader/V3/OpenApiEncodingDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal static partial class OpenApiV3Deserializer
4444
}
4545
},
4646
{
47-
"allowedReserved",
47+
"allowReserved",
4848
(o, n, _) =>
4949
{
5050
var allowReserved = n.GetScalarValue();

src/Microsoft.OpenApi/Reader/V31/OpenApiEncodingDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal static partial class OpenApiV31Deserializer
4343
}
4444
},
4545
{
46-
"allowedReserved", (o, n, _) =>
46+
"allowReserved", (o, n, _) =>
4747
{
4848
var allowReserved = n.GetScalarValue();
4949
if (allowReserved is not null)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.IO;
5+
using System.Threading.Tasks;
6+
using Microsoft.OpenApi.Reader;
7+
using Xunit;
8+
9+
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
10+
{
11+
[Collection("DefaultSettings")]
12+
public class OpenApiEncodingTests
13+
{
14+
private const string SampleFolderPath = "V31Tests/Samples/OpenApiEncoding/";
15+
16+
[Fact]
17+
public async Task ParseEncodingWithAllowReservedShouldSucceed()
18+
{
19+
// Act
20+
var encoding = await OpenApiModelFactory.LoadAsync<OpenApiEncoding>(Path.Combine(SampleFolderPath, "encodingWithAllowReserved.yaml"), OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
21+
22+
// Assert
23+
Assert.Equivalent(
24+
new OpenApiEncoding
25+
{
26+
ContentType = "application/x-www-form-urlencoded",
27+
Style = ParameterStyle.Form,
28+
Explode = true,
29+
AllowReserved = true
30+
}, encoding);
31+
}
32+
}
33+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#encodingObject
2+
contentType: application/x-www-form-urlencoded
3+
style: form
4+
explode: true
5+
allowReserved: true

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,22 @@ public async Task ParseAdvancedEncodingShouldSucceed()
5555
}
5656
}, encoding);
5757
}
58+
59+
[Fact]
60+
public async Task ParseEncodingWithAllowReservedShouldSucceed()
61+
{
62+
// Act
63+
var encoding = await OpenApiModelFactory.LoadAsync<OpenApiEncoding>(Path.Combine(SampleFolderPath, "encodingWithAllowReserved.yaml"), OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings);
64+
65+
// Assert
66+
Assert.Equivalent(
67+
new OpenApiEncoding
68+
{
69+
ContentType = "application/x-www-form-urlencoded",
70+
Style = ParameterStyle.Form,
71+
Explode = true,
72+
AllowReserved = true
73+
}, encoding);
74+
}
5875
}
5976
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#encodingObject
2+
contentType: application/x-www-form-urlencoded
3+
style: form
4+
explode: true
5+
allowReserved: true

0 commit comments

Comments
 (0)