@@ -20,11 +20,27 @@ public static class OpenApiSerializableExtensions
2020 /// <param name="element">The Open API element.</param>
2121 /// <param name="stream">The output stream.</param>
2222 /// <param name="specVersion">The Open API specification version.</param>
23+ /// <param name="settings">Optional JSON writer settings to control output formatting (e.g. compact vs indented).</param>
2324 /// <param name="cancellationToken">The cancellation token.</param>
24- public static Task SerializeAsJsonAsync < T > ( this T element , Stream stream , OpenApiSpecVersion specVersion , CancellationToken cancellationToken = default )
25+ public static Task SerializeAsJsonAsync < T > ( this T element , Stream stream , OpenApiSpecVersion specVersion , OpenApiJsonWriterSettings ? settings = null , CancellationToken cancellationToken = default )
2526 where T : IOpenApiSerializable
2627 {
27- return element . SerializeAsync ( stream , specVersion , OpenApiConstants . Json , cancellationToken ) ;
28+ return element . SerializeAsync ( stream , specVersion , OpenApiConstants . Json , settings , cancellationToken ) ;
29+ }
30+
31+ // 3.5 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
32+ /// <summary>
33+ /// Serialize the <see cref="IOpenApiSerializable"/> to the Open API document (JSON) using the given stream and specification version.
34+ /// </summary>
35+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
36+ /// <param name="element">The Open API element.</param>
37+ /// <param name="stream">The output stream.</param>
38+ /// <param name="specVersion">The Open API specification version.</param>
39+ /// <param name="cancellationToken">The cancellation token.</param>
40+ public static Task SerializeAsJsonAsync < T > ( this T element , Stream stream , OpenApiSpecVersion specVersion , CancellationToken cancellationToken )
41+ where T : IOpenApiSerializable
42+ {
43+ return element . SerializeAsJsonAsync ( stream , specVersion , null , cancellationToken ) ;
2844 }
2945
3046 /// <summary>
@@ -41,6 +57,7 @@ public static Task SerializeAsYamlAsync<T>(this T element, Stream stream, OpenAp
4157 return element . SerializeAsync ( stream , specVersion , OpenApiConstants . Yaml , cancellationToken ) ;
4258 }
4359
60+ // 3.5 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
4461 /// <summary>
4562 /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
4663 /// the given stream, specification version and the format.
@@ -56,7 +73,7 @@ public static Task SerializeAsync<T>(
5673 Stream stream ,
5774 OpenApiSpecVersion specVersion ,
5875 string format ,
59- CancellationToken cancellationToken = default )
76+ CancellationToken cancellationToken )
6077 where T : IOpenApiSerializable
6178 {
6279 return element . SerializeAsync ( stream , specVersion , format , null , cancellationToken ) ;
@@ -96,6 +113,7 @@ public static Task SerializeAsync<T>(
96113 return element . SerializeAsync ( writer , specVersion , cancellationToken ) ;
97114 }
98115
116+ // 3.5 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
99117 /// <summary>
100118 /// Serializes the <see cref="IOpenApiSerializable"/> to Open API document using the given specification version and writer.
101119 /// </summary>
@@ -104,7 +122,7 @@ public static Task SerializeAsync<T>(
104122 /// <param name="writer">The output writer.</param>
105123 /// <param name="specVersion">Version of the specification the output should conform to</param>
106124 /// <param name="cancellationToken">The cancellation token.</param>
107- public static Task SerializeAsync < T > ( this T element , IOpenApiWriter writer , OpenApiSpecVersion specVersion , CancellationToken cancellationToken = default )
125+ public static Task SerializeAsync < T > ( this T element , IOpenApiWriter writer , OpenApiSpecVersion specVersion , CancellationToken cancellationToken )
108126 where T : IOpenApiSerializable
109127 {
110128 Utils . CheckArgumentNull ( element ) ;
@@ -141,16 +159,49 @@ public static Task SerializeAsync<T>(this T element, IOpenApiWriter writer, Open
141159 /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
142160 /// <param name="element">The Open API element.</param>
143161 /// <param name="specVersion">The Open API specification version.</param>
162+ /// <param name="settings">JSON writer settings to control output formatting (e.g. compact vs indented).</param>
144163 /// <param name="cancellationToken">The cancellation token.</param>
145164 public static Task < string > SerializeAsJsonAsync < T > (
146165 this T element ,
147166 OpenApiSpecVersion specVersion ,
148- CancellationToken cancellationToken = default )
167+ OpenApiJsonWriterSettings settings ,
168+ CancellationToken cancellationToken )
169+ where T : IOpenApiSerializable
170+ {
171+ return element . SerializeAsync ( specVersion , OpenApiConstants . Json , settings , cancellationToken ) ;
172+ }
173+
174+ // 3.5 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
175+ /// <summary>
176+ /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in JSON format.
177+ /// </summary>
178+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
179+ /// <param name="element">The Open API element.</param>
180+ /// <param name="specVersion">The Open API specification version.</param>
181+ /// <param name="cancellationToken">The cancellation token.</param>
182+ public static Task < string > SerializeAsJsonAsync < T > (
183+ this T element ,
184+ OpenApiSpecVersion specVersion ,
185+ CancellationToken cancellationToken )
149186 where T : IOpenApiSerializable
150187 {
151188 return element . SerializeAsync ( specVersion , OpenApiConstants . Json , cancellationToken ) ;
152189 }
153190
191+ /// <summary>
192+ /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in JSON format using default settings.
193+ /// </summary>
194+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
195+ /// <param name="element">The Open API element.</param>
196+ /// <param name="specVersion">The Open API specification version.</param>
197+ public static Task < string > SerializeAsJsonAsync < T > (
198+ this T element ,
199+ OpenApiSpecVersion specVersion )
200+ where T : IOpenApiSerializable
201+ {
202+ return element . SerializeAsJsonAsync ( specVersion , default ( CancellationToken ) ) ;
203+ }
204+
154205 /// <summary>
155206 /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in YAML format.
156207 /// </summary>
@@ -174,18 +225,20 @@ public static Task<string> SerializeAsYamlAsync<T>(
174225 /// <param name="element">The Open API element.</param>
175226 /// <param name="specVersion">The Open API specification version.</param>
176227 /// <param name="format">Open API document format.</param>
228+ /// <param name="settings">Provide configuration settings for controlling writing output</param>
177229 /// <param name="cancellationToken">The cancellation token.</param>
178230 public static async Task < string > SerializeAsync < T > (
179231 this T element ,
180232 OpenApiSpecVersion specVersion ,
181233 string format ,
182- CancellationToken cancellationToken = default )
234+ OpenApiWriterSettings settings ,
235+ CancellationToken cancellationToken )
183236 where T : IOpenApiSerializable
184237 {
185238 Utils . CheckArgumentNull ( element ) ;
186239
187240 using var stream = new MemoryStream ( ) ;
188- await element . SerializeAsync ( stream , specVersion , format , cancellationToken ) . ConfigureAwait ( false ) ;
241+ await element . SerializeAsync ( stream , specVersion , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
189242 stream . Position = 0 ;
190243
191244 using var streamReader = new StreamReader ( stream ) ;
@@ -195,5 +248,40 @@ public static async Task<string> SerializeAsync<T>(
195248 return await streamReader . ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
196249#endif
197250 }
251+
252+ // 3.5 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
253+ /// <summary>
254+ /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in the given format.
255+ /// </summary>
256+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
257+ /// <param name="element">The Open API element.</param>
258+ /// <param name="specVersion">The Open API specification version.</param>
259+ /// <param name="format">Open API document format.</param>
260+ /// <param name="cancellationToken">The cancellation token.</param>
261+ public static Task < string > SerializeAsync < T > (
262+ this T element ,
263+ OpenApiSpecVersion specVersion ,
264+ string format ,
265+ CancellationToken cancellationToken )
266+ where T : IOpenApiSerializable
267+ {
268+ return element . SerializeAsync ( specVersion , format , new OpenApiWriterSettings ( ) , cancellationToken ) ;
269+ }
270+
271+ /// <summary>
272+ /// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in the given format using default settings.
273+ /// </summary>
274+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
275+ /// <param name="element">The Open API element.</param>
276+ /// <param name="specVersion">The Open API specification version.</param>
277+ /// <param name="format">Open API document format.</param>
278+ public static Task < string > SerializeAsync < T > (
279+ this T element ,
280+ OpenApiSpecVersion specVersion ,
281+ string format )
282+ where T : IOpenApiSerializable
283+ {
284+ return element . SerializeAsync ( specVersion , format , default ( CancellationToken ) ) ;
285+ }
198286 }
199287}
0 commit comments