Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.OpenApi.Models
/// </summary>
public class OpenApiParameter : IOpenApiSerializable, IOpenApiReferenceable, IOpenApiExtensible
{
private bool? _explode;

/// <summary>
/// Indicates if object is populated with data or is just a reference to the data
/// </summary>
Expand Down Expand Up @@ -79,7 +81,11 @@ public class OpenApiParameter : IOpenApiSerializable, IOpenApiReferenceable, IOp
/// When style is form, the default value is true.
/// For all other styles, the default value is false.
/// </summary>
public bool Explode { get; set; }
public bool Explode
{
get => _explode ?? Style == ParameterStyle.Form;
set => _explode = value;
}

/// <summary>
/// Determines whether the parameter value SHOULD allow reserved characters,
Expand Down
18 changes: 18 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ public OpenApiParameterTests(ITestOutputHelper output)
_output = output;
}

[Theory]
[InlineData(ParameterStyle.Form, true)]
[InlineData(ParameterStyle.SpaceDelimited, false)]
[InlineData(null, false)]
public void WhenStyleIsFormTheDefaultValueOfExplodeShouldBeTrueOtherwiseFalse(ParameterStyle? style, bool expectedExplode)
{
// Arrange
var parameter = new OpenApiParameter
{
Name = "name1",
In = ParameterLocation.Query,
Style = style
};

// Act & Assert
parameter.Explode.Should().Be(expectedExplode);
}

[Fact]
public void SerializeBasicParameterAsV3JsonWorks()
{
Expand Down