Skip to content

Commit bb8b087

Browse files
authored
Merge pull request #492 from CumpsD/master
Make default parameter overloads binary compatible
2 parents e59b568 + ad32cc4 commit bb8b087

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

100644100755
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpec
4141
element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
4242
}
4343

44+
/// <summary>
45+
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
46+
/// the given stream, specification version and the format.
47+
/// </summary>
48+
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
49+
/// <param name="element">The Open API element.</param>
50+
/// <param name="stream">The given stream.</param>
51+
/// <param name="specVersion">The Open API specification version.</param>
52+
/// <param name="format">The output format (JSON or YAML).</param>
53+
public static void Serialize<T>(
54+
this T element,
55+
Stream stream,
56+
OpenApiSpecVersion specVersion,
57+
OpenApiFormat format)
58+
where T : IOpenApiSerializable
59+
{
60+
element.Serialize(stream, specVersion, format, null);
61+
}
62+
4463
/// <summary>
4564
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
4665
/// the given stream, specification version and the format.
@@ -56,7 +75,7 @@ public static void Serialize<T>(
5675
Stream stream,
5776
OpenApiSpecVersion specVersion,
5877
OpenApiFormat format,
59-
OpenApiWriterSettings settings = null)
78+
OpenApiWriterSettings settings)
6079
where T : IOpenApiSerializable
6180
{
6281
if (stream == null)

src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs

100644100755
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ namespace Microsoft.OpenApi.Writers
1010
/// </summary>
1111
public class OpenApiJsonWriter : OpenApiWriterBase
1212
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
15+
/// </summary>
16+
/// <param name="textWriter">The text writer.</param>
17+
public OpenApiJsonWriter(TextWriter textWriter) : base(textWriter, null)
18+
{
19+
}
20+
1321
/// <summary>
1422
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
1523
/// </summary>
1624
/// <param name="textWriter">The text writer.</param>
1725
/// <param name="settings">Settings for controlling how the OpenAPI document will be written out.</param>
18-
public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings settings = null) : base(textWriter, settings)
26+
public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings settings) : base(textWriter, settings)
1927
{
2028
}
2129

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

100644100755
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using Microsoft.OpenApi.Exceptions;
8-
using Microsoft.OpenApi.Models;
98
using Microsoft.OpenApi.Properties;
109

1110
namespace Microsoft.OpenApi.Writers
@@ -40,25 +39,27 @@ public abstract class OpenApiWriterBase : IOpenApiWriter
4039
/// Initializes a new instance of the <see cref="OpenApiWriterBase"/> class.
4140
/// </summary>
4241
/// <param name="textWriter">The text writer.</param>
43-
public OpenApiWriterBase(TextWriter textWriter)
42+
public OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null)
4443
{
45-
Writer = textWriter;
46-
Writer.NewLine = "\n";
47-
48-
Scopes = new Stack<Scope>();
4944
}
5045

5146
/// <summary>
5247
/// Initializes a new instance of the <see cref="OpenApiWriterBase"/> class.
5348
/// </summary>
5449
/// <param name="textWriter"></param>
5550
/// <param name="settings"></param>
56-
public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings = null) : this(textWriter)
51+
public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings)
5752
{
53+
Writer = textWriter;
54+
Writer.NewLine = "\n";
55+
56+
Scopes = new Stack<Scope>();
57+
5858
if (settings == null)
5959
{
6060
settings = new OpenApiWriterSettings();
6161
}
62+
6263
Settings = settings;
6364
}
6465

src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs

100644100755
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ namespace Microsoft.OpenApi.Writers
1010
/// </summary>
1111
public class OpenApiYamlWriter : OpenApiWriterBase
1212
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="OpenApiYamlWriter"/> class.
15+
/// </summary>
16+
/// <param name="textWriter">The text writer.</param>
17+
public OpenApiYamlWriter(TextWriter textWriter) : this(textWriter, null)
18+
{
19+
}
20+
1321
/// <summary>
1422
/// Initializes a new instance of the <see cref="OpenApiYamlWriter"/> class.
1523
/// </summary>
1624
/// <param name="textWriter">The text writer.</param>
1725
/// <param name="settings"></param>
18-
public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings settings = null) : base(textWriter, settings)
26+
public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings settings) : base(textWriter, settings)
1927
{
20-
2128
}
2229

2330
/// <summary>

0 commit comments

Comments
 (0)