@@ -13,6 +13,10 @@ namespace Microsoft.OpenApi.Models
1313 /// </summary>
1414 public class OpenApiEncoding : IOpenApiSerializable , IOpenApiExtensible
1515 {
16+ /// <summary>
17+ /// Explode backing variable
18+ /// </summary>
19+ private bool ? _explode ;
1620 /// <summary>
1721 /// The Content-Type for encoding a specific property.
1822 /// The value can be a specific media type (e.g. application/json),
@@ -37,7 +41,11 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
3741 /// For all other styles, the default value is false.
3842 /// This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.
3943 /// </summary>
40- public bool ? Explode { get ; set ; }
44+ public bool ? Explode
45+ {
46+ get => _explode ?? Style == ParameterStyle . Form ;
47+ set => _explode = value ;
48+ }
4149
4250 /// <summary>
4351 /// Determines whether the parameter value SHOULD allow reserved characters,
@@ -65,7 +73,7 @@ public OpenApiEncoding(OpenApiEncoding encoding)
6573 ContentType = encoding ? . ContentType ?? ContentType ;
6674 Headers = encoding ? . Headers != null ? new Dictionary < string , OpenApiHeader > ( encoding . Headers ) : null ;
6775 Style = encoding ? . Style ?? Style ;
68- Explode = encoding ? . Explode ?? Explode ;
76+ Explode = encoding ? . _explode ;
6977 AllowReserved = encoding ? . AllowReserved ?? AllowReserved ;
7078 Extensions = encoding ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( encoding . Extensions ) : null ;
7179 }
@@ -89,7 +97,10 @@ public void SerializeAsV3(IOpenApiWriter writer)
8997 writer . WriteProperty ( OpenApiConstants . Style , Style ? . GetDisplayName ( ) ) ;
9098
9199 // explode
92- writer . WriteProperty ( OpenApiConstants . Explode , Explode , false ) ;
100+ if ( _explode . HasValue )
101+ {
102+ writer . WriteProperty ( OpenApiConstants . Explode , Explode ) ;
103+ }
93104
94105 // allowReserved
95106 writer . WriteProperty ( OpenApiConstants . AllowReserved , AllowReserved , false ) ;
0 commit comments