Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(writerextensions): consistency #72

Merged
merged 2 commits into from
Nov 24, 2022
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
32 changes: 16 additions & 16 deletions src/LEGO.AsyncAPI/Models/AsyncApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,43 +255,43 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)
writer.WriteOptionalProperty(AsyncApiConstants.Title, this.Title);

// multipleOf
writer.WriteProperty(AsyncApiConstants.MultipleOf, this.MultipleOf);
writer.WriteOptionalProperty(AsyncApiConstants.MultipleOf, this.MultipleOf);

// maximum
writer.WriteProperty(AsyncApiConstants.Maximum, this.Maximum);
writer.WriteOptionalProperty(AsyncApiConstants.Maximum, this.Maximum);

// exclusiveMaximum
writer.WriteProperty(AsyncApiConstants.ExclusiveMaximum, this.ExclusiveMaximum);
writer.WriteOptionalProperty(AsyncApiConstants.ExclusiveMaximum, this.ExclusiveMaximum);

// minimum
writer.WriteProperty(AsyncApiConstants.Minimum, this.Minimum);
writer.WriteOptionalProperty(AsyncApiConstants.Minimum, this.Minimum);

// exclusiveMinimum
writer.WriteProperty(AsyncApiConstants.ExclusiveMinimum, this.ExclusiveMinimum);
writer.WriteOptionalProperty(AsyncApiConstants.ExclusiveMinimum, this.ExclusiveMinimum);

// maxLength
writer.WriteProperty(AsyncApiConstants.MaxLength, this.MaxLength);
writer.WriteOptionalProperty(AsyncApiConstants.MaxLength, this.MaxLength);

// minLength
writer.WriteProperty(AsyncApiConstants.MinLength, this.MinLength);
writer.WriteOptionalProperty(AsyncApiConstants.MinLength, this.MinLength);

// pattern
writer.WriteOptionalProperty(AsyncApiConstants.Pattern, this.Pattern);

// maxItems
writer.WriteProperty(AsyncApiConstants.MaxItems, this.MaxItems);
writer.WriteOptionalProperty(AsyncApiConstants.MaxItems, this.MaxItems);

// minItems
writer.WriteProperty(AsyncApiConstants.MinItems, this.MinItems);
writer.WriteOptionalProperty(AsyncApiConstants.MinItems, this.MinItems);

// uniqueItems
writer.WriteProperty(AsyncApiConstants.UniqueItems, this.UniqueItems);
writer.WriteOptionalProperty(AsyncApiConstants.UniqueItems, this.UniqueItems);

// maxProperties
writer.WriteProperty(AsyncApiConstants.MaxProperties, this.MaxProperties);
writer.WriteOptionalProperty(AsyncApiConstants.MaxProperties, this.MaxProperties);

// minProperties
writer.WriteProperty(AsyncApiConstants.MinProperties, this.MinProperties);
writer.WriteOptionalProperty(AsyncApiConstants.MinProperties, this.MinProperties);

// required
writer.WriteOptionalCollection(AsyncApiConstants.Required, this.Required, (w, s) => w.WriteValue(s));
Expand Down Expand Up @@ -357,16 +357,16 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)
writer.WriteOptionalObject(AsyncApiConstants.Default, this.Default, (w, d) => w.WriteAny(d));

// nullable
writer.WriteProperty(AsyncApiConstants.Nullable, this.Nullable, false);
writer.WriteOptionalProperty(AsyncApiConstants.Nullable, this.Nullable, false);

// discriminator
writer.WriteOptionalProperty(AsyncApiConstants.Discriminator, this.Discriminator);

// readOnly
writer.WriteProperty(AsyncApiConstants.ReadOnly, this.ReadOnly, false);
writer.WriteOptionalProperty(AsyncApiConstants.ReadOnly, this.ReadOnly, false);

// writeOnly
writer.WriteProperty(AsyncApiConstants.WriteOnly, this.WriteOnly, false);
writer.WriteOptionalProperty(AsyncApiConstants.WriteOnly, this.WriteOnly, false);

// externalDocs
writer.WriteOptionalObject(AsyncApiConstants.ExternalDocs, this.ExternalDocs, (w, s) => s.SerializeV2(w));
Expand All @@ -375,7 +375,7 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)
writer.WriteOptionalCollection(AsyncApiConstants.Examples, this.Examples, (w, e) => w.WriteAny(e));

// deprecated
writer.WriteProperty(AsyncApiConstants.Deprecated, this.Deprecated, false);
writer.WriteOptionalProperty(AsyncApiConstants.Deprecated, this.Deprecated, false);

// extensions
writer.WriteExtensions(this.Extensions, AsyncApiVersion.AsyncApi2_3_0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)

writer.WriteStartObject();

writer.WriteRequiredObject(AsyncApiConstants.Headers, Headers, (w, h) => h.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.Headers, Headers, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, BindingVersion);

writer.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)
writer.WriteStartObject();

writer.WriteRequiredProperty(AsyncApiConstants.Type, Type);
writer.WriteRequiredProperty(AsyncApiConstants.Method, Method);
writer.WriteRequiredObject(AsyncApiConstants.Query, Query, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.Method, Method);
writer.WriteOptionalObject(AsyncApiConstants.Query, Query, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, BindingVersion);

writer.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)

writer.WriteStartObject();
writer.WriteOptionalProperty(AsyncApiConstants.Topic, Topic);
writer.WriteProperty(AsyncApiConstants.Partitions, Partitions);
writer.WriteProperty(AsyncApiConstants.Replicas, Replicas);
writer.WriteOptionalProperty<int>(AsyncApiConstants.Partitions, Partitions);
writer.WriteOptionalProperty<int>(AsyncApiConstants.Replicas, Replicas);
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, BindingVersion);

writer.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)

writer.WriteStartObject();

writer.WriteRequiredObject(AsyncApiConstants.Key, Key, (w, h) => h.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.Key, Key, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.SchemaIdLocation, SchemaIdLocation);
writer.WriteOptionalProperty(AsyncApiConstants.SchemaIdPayloadEncoding, SchemaIdPayloadEncoding);
writer.WriteOptionalProperty(AsyncApiConstants.SchemaLookupStrategy, SchemaLookupStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void SerializeV2WithoutReference(IAsyncApiWriter writer)
}

writer.WriteStartObject();
writer.WriteRequiredObject(AsyncApiConstants.GroupId, GroupId, (w, h) => h.SerializeV2(w));
writer.WriteRequiredObject(AsyncApiConstants.ClientId, ClientId, (w, h) => h.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.GroupId, GroupId, (w, h) => h.SerializeV2(w));
writer.WriteOptionalObject(AsyncApiConstants.ClientId, ClientId, (w, h) => h.SerializeV2(w));
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, BindingVersion);

writer.WriteEndObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void WriteRequiredProperty(this IAsyncApiWriter writer, string nam
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <param name="defaultValue">The default boolean value.</param>
public static void WriteProperty(this IAsyncApiWriter writer, string name, bool value, bool defaultValue = false)
public static void WriteOptionalProperty(this IAsyncApiWriter writer, string name, bool value, bool defaultValue = false)
{
if (value == defaultValue)
{
Expand All @@ -74,7 +74,7 @@ public static void WriteProperty(this IAsyncApiWriter writer, string name, bool
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
/// <param name="defaultValue">The default boolean value.</param>
public static void WriteProperty(
public static void WriteOptionalProperty(
this IAsyncApiWriter writer,
string name,
bool? value,
Expand All @@ -96,15 +96,15 @@ public static void WriteProperty(
/// <param name="writer">The writer.</param>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
public static void WriteProperty<T>(this IAsyncApiWriter writer, string name, T? value)
public static void WriteOptionalProperty<T>(this IAsyncApiWriter writer, string name, T? value)
where T : struct
{
if (value == null)
{
return;
}

writer.WriteProperty(name, value.Value);
writer.WriteRequiredProperty(name, value.Value);
}

/// <summary>
Expand All @@ -113,7 +113,7 @@ public static void WriteProperty<T>(this IAsyncApiWriter writer, string name, T?
/// <param name="writer">The writer.</param>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
public static void WriteProperty<T>(this IAsyncApiWriter writer, string name, T value)
public static void WriteRequiredProperty<T>(this IAsyncApiWriter writer, string name, T value)
where T : struct
{
CheckArguments(writer, name);
Expand Down