diff --git a/src/LEGO.AsyncAPI/Models/AsyncApiSerializableExtensions.cs b/src/LEGO.AsyncAPI/Models/AsyncApiSerializableExtensions.cs index 4fed2c4a..c71bfd25 100644 --- a/src/LEGO.AsyncAPI/Models/AsyncApiSerializableExtensions.cs +++ b/src/LEGO.AsyncAPI/Models/AsyncApiSerializableExtensions.cs @@ -19,10 +19,25 @@ public static class AsyncApiSerializableExtensions /// The AsyncApi element. /// The output stream. /// The AsyncApi specification version. + [Obsolete($"Please use overridden version that accepts a {nameof(AsyncApiWriterSettings)} instance.")] public static void SerializeAsJson(this T element, Stream stream, AsyncApiVersion specificationVersion) where T : IAsyncApiSerializable { - element.Serialize(stream, specificationVersion, AsyncApiFormat.Json); + element.SerializeAsJson(stream, specificationVersion, AsyncApiWriterSettings.Default); + } + + /// + /// Serialize the to the AsyncApi document (JSON) using the given stream and specification version. + /// + /// the . + /// The AsyncApi element. + /// The output stream. + /// The AsyncApi specification version. + /// The settings used for writing + public static void SerializeAsJson(this T element, Stream stream, AsyncApiVersion specificationVersion, AsyncApiWriterSettings settings) + where T : IAsyncApiSerializable + { + element.Serialize(stream, specificationVersion, AsyncApiFormat.Json, settings); } /// @@ -32,10 +47,25 @@ public static void SerializeAsJson(this T element, Stream stream, AsyncApiVer /// The AsyncApi element. /// The output stream. /// The AsyncApi specification version. + [Obsolete($"Please use overridden version that accepts a {nameof(AsyncApiWriterSettings)} instance.")] public static void SerializeAsYaml(this T element, Stream stream, AsyncApiVersion specificationVersion) where T : IAsyncApiSerializable { - element.Serialize(stream, specificationVersion, AsyncApiFormat.Yaml); + element.SerializeAsYaml(stream, specificationVersion, AsyncApiWriterSettings.Default); + } + + /// + /// Serializes the to the AsyncApi document (YAML) using the given stream and specification version. + /// + /// the . + /// The AsyncApi element. + /// The output stream. + /// The AsyncApi specification version. + /// The settings used for writing + public static void SerializeAsYaml(this T element, Stream stream, AsyncApiVersion specificationVersion, AsyncApiWriterSettings settings) + where T : IAsyncApiSerializable + { + element.Serialize(stream, specificationVersion, AsyncApiFormat.Yaml, settings); } /// @@ -45,7 +75,7 @@ public static void SerializeAsYaml(this T element, Stream stream, AsyncApiVer /// the . /// The AsyncApi element. /// The given stream. - /// The AsyncApi specification version. + /// The AsyncApi specification version. /// The output format (JSON or YAML). [Obsolete($"Please use overridden version that accepts a {nameof(AsyncApiWriterSettings)} instance.")] public static void Serialize( diff --git a/src/LEGO.AsyncAPI/Writers/AsyncApiWriterSettings.cs b/src/LEGO.AsyncAPI/Writers/AsyncApiWriterSettings.cs index 0b747c0f..2b663bb2 100644 --- a/src/LEGO.AsyncAPI/Writers/AsyncApiWriterSettings.cs +++ b/src/LEGO.AsyncAPI/Writers/AsyncApiWriterSettings.cs @@ -4,11 +4,31 @@ namespace LEGO.AsyncAPI.Writers { using LEGO.AsyncAPI.Models; + /// + /// Contains settings for writing async api. + /// public class AsyncApiWriterSettings : AsyncApiSettings { private ReferenceInlineSetting referenceInline = ReferenceInlineSetting.DoNotInlineReferences; - internal LoopDetector LoopDetector { get; } = new LoopDetector(); + static AsyncApiWriterSettings() + { + Default = new AsyncApiWriterSettings(); + } + + /// + /// Initializes a new instance of the class. + /// + public AsyncApiWriterSettings() + { + this.InlineReferences = false; + this.LoopDetector = new LoopDetector(); + } + + /// + /// Gets the default settings to use for writing async api. + /// + public static AsyncApiWriterSettings Default { get; } /// /// Gets or sets indicates how references in the source document should be handled. @@ -38,8 +58,18 @@ public ReferenceInlineSetting ReferenceInline /// /// Gets or sets a value indicating whether indicates if local references should be rendered as an inline object. /// - public bool InlineReferences { get; set; } = false; + public bool InlineReferences { get; set; } + /// + /// Figures out if a loop exists. + /// + internal LoopDetector LoopDetector { get; } + + /// + /// Returns back if the refernece should be inlined or not. + /// + /// The refernece. + /// True if it should be inlined otherwise false. public bool ShouldInlineReference(AsyncApiReference reference) { return this.InlineReferences;