Skip to content

Remove KeyComparer property from OpenApiWriterSettings #2375

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

Merged
merged 5 commits into from
Jun 4, 2025
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
50 changes: 0 additions & 50 deletions src/Microsoft.OpenApi/Extensions/CollectionExtensions.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// <param name="writer">The writer.</param>
/// <param name="name">The property name.</param>
/// <param name="value">The property value.</param>
public static void WriteProperty(this IOpenApiWriter writer, string name, string? value)

Check warning on line 23 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'WriteProperty' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)

Check warning on line 23 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'WriteProperty' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
{
if (value == null)
{
Expand Down Expand Up @@ -139,7 +139,7 @@
T? value,
Action<IOpenApiWriter, T> action)
{
if (value != null)

Check warning on line 142 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)

Check warning on line 142 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)
{
if (value is IEnumerable values && !values.GetEnumerator().MoveNext())
{
Expand Down Expand Up @@ -167,7 +167,7 @@
Utils.CheckArgumentNull(action);

writer.WritePropertyName(name);
if (value != null)

Check warning on line 170 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)

Check warning on line 170 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)
{
action(writer, value);
}
Expand Down Expand Up @@ -262,7 +262,7 @@
/// <param name="name">The property name.</param>
/// <param name="elements">The map values.</param>
/// <param name="action">The map element writer action.</param>
public static void WriteRequiredMap(

Check warning on line 265 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'WriteRequiredMap' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)

Check warning on line 265 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'WriteRequiredMap' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
this IOpenApiWriter writer,
string name,
IDictionary<string, string>? elements,
Expand Down Expand Up @@ -419,16 +419,9 @@
writer.WriteStartArray();
if (elements != null)
{
var settings = writer.GetSettings();

if (settings?.KeyComparer is IComparer<T> typedComparer)
{
elements = elements.Sort(typedComparer);
}

foreach (var item in elements)
{
if (item != null)

Check warning on line 424 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)
{
action(writer, item);
}
Expand Down Expand Up @@ -464,16 +457,10 @@

if (elements != null)
{
var settings = writer.GetSettings();
if (settings?.KeyComparer != null)
{
elements = elements.Sort(settings.KeyComparer); // sort using custom comparer
}

foreach (var item in elements)
{
writer.WritePropertyName(item.Key);
if (item.Value != null)

Check warning on line 463 in src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Use a comparison to 'default(T)' instead or add a constraint to 'T' so that it can't be a value type. (https://rules.sonarsource.com/csharp/RSPEC-2955)
{
action(writer, item.Key, item.Value);
}
Expand Down
9 changes: 1 addition & 8 deletions src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;

namespace Microsoft.OpenApi
namespace Microsoft.OpenApi
{
/// <summary>
/// Configuration settings to control how OpenAPI documents are written
Expand All @@ -23,10 +21,5 @@ internal bool ShouldInlineReference(OpenApiReference reference)
return (reference.IsLocal && InlineLocalReferences)
|| (reference.IsExternal && InlineExternalReferences);
}

/// <summary>
/// Specifies a comparer used to sort string-based collection keys, such as components or tags.
/// </summary>
public IComparer<string>? KeyComparer { get; set; }
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading