@@ -38,7 +38,9 @@ public static Task SerializeAsJsonAsync<T>(this T element, Stream stream, OpenAp
3838 /// <param name="specVersion">The Open API specification version.</param>
3939 /// <param name="settings">Settings controlling JSON output, including <see cref="OpenApiJsonWriterSettings.Terse"/> for compact formatting.</param>
4040 /// <param name="cancellationToken">The cancellation token.</param>
41- public static Task SerializeAsJsonAsync < T > ( this T element , Stream stream , OpenApiSpecVersion specVersion , OpenApiJsonWriterSettings settings , CancellationToken cancellationToken )
41+ #pragma warning disable RS0026 // Intentional overload alongside the CancellationToken-only variant; types are unambiguous.
42+ public static Task SerializeAsJsonAsync < T > ( this T element , Stream stream , OpenApiSpecVersion specVersion , OpenApiJsonWriterSettings settings , CancellationToken cancellationToken = default )
43+ #pragma warning restore RS0026
4244 where T : IOpenApiSerializable
4345 {
4446 return element . SerializeAsync ( stream , specVersion , OpenApiConstants . Json , settings , cancellationToken ) ;
@@ -68,12 +70,14 @@ public static Task SerializeAsYamlAsync<T>(this T element, Stream stream, OpenAp
6870 /// <param name="specVersion">The Open API specification version.</param>
6971 /// <param name="format">The output format (JSON or YAML).</param>
7072 /// <param name="cancellationToken">The cancellation token.</param>
73+ #pragma warning disable RS0027 // The settings overload below has the same parameter count but different types; no ambiguity exists.
7174 public static Task SerializeAsync < T > (
7275 this T element ,
7376 Stream stream ,
7477 OpenApiSpecVersion specVersion ,
7578 string format ,
7679 CancellationToken cancellationToken = default )
80+ #pragma warning restore RS0027
7781 where T : IOpenApiSerializable
7882 {
7983 return element . SerializeAsync ( stream , specVersion , format , null , cancellationToken ) ;
@@ -179,13 +183,17 @@ public static Task<string> SerializeAsJsonAsync<T>(
179183 /// <param name="element">The Open API element.</param>
180184 /// <param name="specVersion">The Open API specification version.</param>
181185 /// <param name="settings">Settings controlling JSON output, including <see cref="OpenApiJsonWriterSettings.Terse"/> for compact formatting.</param>
186+ /// <param name="cancellationToken">The cancellation token.</param>
187+ #pragma warning disable RS0026 // Intentional overload alongside the CancellationToken-only variant; types are unambiguous.
182188 public static Task < string > SerializeAsJsonAsync < T > (
183189 this T element ,
184190 OpenApiSpecVersion specVersion ,
185- OpenApiJsonWriterSettings settings )
191+ OpenApiJsonWriterSettings settings ,
192+ CancellationToken cancellationToken = default )
193+ #pragma warning restore RS0026
186194 where T : IOpenApiSerializable
187195 {
188- return element . SerializeAsync ( specVersion , OpenApiConstants . Json , settings ) ;
196+ return element . SerializeAsync ( specVersion , OpenApiConstants . Json , settings , cancellationToken ) ;
189197 }
190198
191199 /// <summary>
@@ -243,21 +251,29 @@ public static async Task<string> SerializeAsync<T>(
243251 /// <param name="specVersion">The Open API specification version.</param>
244252 /// <param name="format">Open API document format.</param>
245253 /// <param name="settings">Provide configuration settings for controlling writing output.</param>
254+ /// <param name="cancellationToken">The cancellation token.</param>
255+ #pragma warning disable RS0026 // Intentional overload alongside the CancellationToken-only variant; types are unambiguous.
246256 public static async Task < string > SerializeAsync < T > (
247257 this T element ,
248258 OpenApiSpecVersion specVersion ,
249259 string format ,
250- OpenApiWriterSettings ? settings )
260+ OpenApiWriterSettings ? settings ,
261+ CancellationToken cancellationToken = default )
262+ #pragma warning restore RS0026
251263 where T : IOpenApiSerializable
252264 {
253265 Utils . CheckArgumentNull ( element ) ;
254266
255267 using var stream = new MemoryStream ( ) ;
256- await element . SerializeAsync ( stream , specVersion , format , settings , CancellationToken . None ) . ConfigureAwait ( false ) ;
268+ await element . SerializeAsync ( stream , specVersion , format , settings , cancellationToken ) . ConfigureAwait ( false ) ;
257269 stream . Position = 0 ;
258270
259271 using var streamReader = new StreamReader ( stream ) ;
272+ #if NET7_0_OR_GREATER
273+ return await streamReader . ReadToEndAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
274+ #else
260275 return await streamReader . ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
276+ #endif
261277 }
262278 }
263279}
0 commit comments