Skip to content

Commit 705b65f

Browse files
authored
Merge pull request #1 from rachael-ross/feat-Add-EnableDefaultSortByIdasOption
Added EnableDefaultSortById
2 parents 6540c12 + 9b07698 commit 705b65f

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/JsonApiDotNetCore/Configuration/IJsonApiOptions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,10 @@ internal NamingStrategy SerializerNamingStrategy
176176
/// </example>
177177
/// </summary>
178178
JsonSerializerSettings SerializerSettings { get; }
179+
180+
/// <summary>
181+
/// If true, will automatically sort resources by Id, if no other sort was specified. Default is true.
182+
/// </summary>
183+
bool EnableDefaultSortById { get; set; }
179184
}
180185
}

src/JsonApiDotNetCore/Configuration/JsonApiOptions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public sealed class JsonApiOptions : IJsonApiOptions
8282
/// <inheritdoc />
8383
public IsolationLevel? TransactionIsolationLevel { get; set; }
8484

85+
/// <inheritdoc />
86+
public bool EnableDefaultSortById { get; set; } = true;
87+
8588
/// <inheritdoc />
8689
public JsonSerializerSettings SerializerSettings { get; } = new JsonSerializerSettings
8790
{

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1515
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1616
<DebugType>embedded</DebugType>
17+
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
1722
</PropertyGroup>
1823

1924
<ItemGroup>

src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ protected virtual SortExpression GetSort(IReadOnlyCollection<QueryExpression> ex
443443

444444
sort = _resourceDefinitionAccessor.OnApplySort(resourceContext.ResourceType, sort);
445445

446-
if (sort == null)
446+
if (sort == null && _options.EnableDefaultSortById)
447447
{
448448
AttrAttribute idAttribute = GetIdAttribute(resourceContext);
449449
sort = new SortExpression(new SortElementExpression(new ResourceFieldChainExpression(idAttribute), true).AsArray());

0 commit comments

Comments
 (0)