Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpec
element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
}

/// <summary>
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
/// the given stream, specification version and the format.
/// </summary>
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
/// <param name="element">The Open API element.</param>
/// <param name="stream">The given stream.</param>
/// <param name="specVersion">The Open API specification version.</param>
/// <param name="format">The output format (JSON or YAML).</param>
public static void Serialize<T>(
this T element,
Stream stream,
OpenApiSpecVersion specVersion,
OpenApiFormat format)
where T : IOpenApiSerializable
{
element.Serialize(stream, specVersion, format, null);
}

/// <summary>
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document using
/// the given stream, specification version and the format.
Expand All @@ -56,7 +75,7 @@ public static void Serialize<T>(
Stream stream,
OpenApiSpecVersion specVersion,
OpenApiFormat format,
OpenApiWriterSettings settings = null)
OpenApiWriterSettings settings)
where T : IOpenApiSerializable
{
if (stream == null)
Expand Down
10 changes: 9 additions & 1 deletion src/Microsoft.OpenApi/Writers/OpenApiJsonWriter.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ namespace Microsoft.OpenApi.Writers
/// </summary>
public class OpenApiJsonWriter : OpenApiWriterBase
{
/// <summary>
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
public OpenApiJsonWriter(TextWriter textWriter) : base(textWriter, null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenApiJsonWriter"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
/// <param name="settings">Settings for controlling how the OpenAPI document will be written out.</param>
public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings settings = null) : base(textWriter, settings)
public OpenApiJsonWriter(TextWriter textWriter, OpenApiWriterSettings settings) : base(textWriter, settings)
{
}

Expand Down
15 changes: 8 additions & 7 deletions src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Properties;

namespace Microsoft.OpenApi.Writers
Expand Down Expand Up @@ -40,25 +39,27 @@ public abstract class OpenApiWriterBase : IOpenApiWriter
/// Initializes a new instance of the <see cref="OpenApiWriterBase"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
public OpenApiWriterBase(TextWriter textWriter)
public OpenApiWriterBase(TextWriter textWriter) : this(textWriter, null)
{
Writer = textWriter;
Writer.NewLine = "\n";

Scopes = new Stack<Scope>();
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenApiWriterBase"/> class.
/// </summary>
/// <param name="textWriter"></param>
/// <param name="settings"></param>
public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings = null) : this(textWriter)
public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings)
{
Writer = textWriter;
Writer.NewLine = "\n";

Scopes = new Stack<Scope>();

if (settings == null)
{
settings = new OpenApiWriterSettings();
}

Settings = settings;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.OpenApi/Writers/OpenApiYamlWriter.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ namespace Microsoft.OpenApi.Writers
/// </summary>
public class OpenApiYamlWriter : OpenApiWriterBase
{
/// <summary>
/// Initializes a new instance of the <see cref="OpenApiYamlWriter"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
public OpenApiYamlWriter(TextWriter textWriter) : this(textWriter, null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="OpenApiYamlWriter"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
/// <param name="settings"></param>
public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings settings = null) : base(textWriter, settings)
public OpenApiYamlWriter(TextWriter textWriter, OpenApiWriterSettings settings) : base(textWriter, settings)
{

}

/// <summary>
Expand Down