Skip to content

Commit 18f2a11

Browse files
When the style property on an OpenApiParameter is 'form' then the default value for the explode property should be true. For all other styles the default value is false. Cover this in a unit test.
1 parent 2db9643 commit 18f2a11

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Microsoft.OpenApi.Models
1414
/// </summary>
1515
public class OpenApiParameter : IOpenApiSerializable, IOpenApiReferenceable, IOpenApiExtensible
1616
{
17+
private bool? _explode;
18+
1719
/// <summary>
1820
/// Indicates if object is populated with data or is just a reference to the data
1921
/// </summary>
@@ -79,7 +81,11 @@ public class OpenApiParameter : IOpenApiSerializable, IOpenApiReferenceable, IOp
7981
/// When style is form, the default value is true.
8082
/// For all other styles, the default value is false.
8183
/// </summary>
82-
public bool Explode { get; set; }
84+
public bool Explode
85+
{
86+
get => _explode ?? Style == ParameterStyle.Form;
87+
set => _explode = value;
88+
}
8389

8490
/// <summary>
8591
/// Determines whether the parameter value SHOULD allow reserved characters,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ public OpenApiParameterTests(ITestOutputHelper output)
163163
_output = output;
164164
}
165165

166+
[Theory]
167+
[InlineData(ParameterStyle.Form, true)]
168+
[InlineData(ParameterStyle.SpaceDelimited, false)]
169+
[InlineData(null, false)]
170+
public void WhenStyleIsFormTheDefaultValueOfExplodeShouldBeTrueOtherwiseFalse(ParameterStyle? style, bool expectedExplode)
171+
{
172+
// Arrange
173+
var parameter = new OpenApiParameter
174+
{
175+
Name = "name1",
176+
In = ParameterLocation.Query,
177+
Style = style
178+
};
179+
180+
// Act & Assert
181+
parameter.Explode.Should().Be(expectedExplode);
182+
}
183+
166184
[Fact]
167185
public void SerializeBasicParameterAsV3JsonWorks()
168186
{

0 commit comments

Comments
 (0)