@@ -11,6 +11,10 @@ namespace Microsoft.OpenApi
1111 /// </summary>
1212 public class OpenApiEncoding : IOpenApiSerializable , IOpenApiExtensible
1313 {
14+ /// <summary>
15+ /// Explode backing variable
16+ /// </summary>
17+ private bool ? _explode ;
1418 /// <summary>
1519 /// The Content-Type for encoding a specific property.
1620 /// The value can be a specific media type (e.g. application/json),
@@ -35,7 +39,11 @@ public class OpenApiEncoding : IOpenApiSerializable, IOpenApiExtensible
3539 /// For all other styles, the default value is false.
3640 /// This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded.
3741 /// </summary>
38- public bool ? Explode { get ; set ; }
42+ public bool ? Explode
43+ {
44+ get => _explode ?? Style == ParameterStyle . Form ;
45+ set => _explode = value ;
46+ }
3947
4048 /// <summary>
4149 /// Determines whether the parameter value SHOULD allow reserved characters,
@@ -63,7 +71,7 @@ public OpenApiEncoding(OpenApiEncoding encoding)
6371 ContentType = encoding ? . ContentType ?? ContentType ;
6472 Headers = encoding ? . Headers != null ? new Dictionary < string , IOpenApiHeader > ( encoding . Headers ) : null ;
6573 Style = encoding ? . Style ?? Style ;
66- Explode = encoding ? . Explode ?? Explode ;
74+ Explode = encoding ? . _explode ;
6775 AllowReserved = encoding ? . AllowReserved ?? AllowReserved ;
6876 Extensions = encoding ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( encoding . Extensions ) : null ;
6977 }
@@ -106,7 +114,10 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
106114 writer . WriteProperty ( OpenApiConstants . Style , Style ? . GetDisplayName ( ) ) ;
107115
108116 // explode
109- writer . WriteProperty ( OpenApiConstants . Explode , Explode , false ) ;
117+ if ( _explode . HasValue )
118+ {
119+ writer . WriteProperty ( OpenApiConstants . Explode , Explode ) ;
120+ }
110121
111122 // allowReserved
112123 writer . WriteProperty ( OpenApiConstants . AllowReserved , AllowReserved , false ) ;
0 commit comments