Skip to content

Commit 31638b8

Browse files
committed
Merge branch 'merge-master-v503-into-openapi' into openapi-required-and-nullable-properties
2 parents c55a2cb + 47320f0 commit 31638b8

File tree

51 files changed

+986
-764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+986
-764
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
]
1010
},
1111
"regitlint": {
12-
"version": "6.0.8",
12+
"version": "6.1.1",
1313
"commands": [
1414
"regitlint"
1515
]

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Please follow these steps to have your contribution considered by the maintainer
5858

5959
We use [CSharpGuidelines](https://csharpcodingguidelines.com/) as our coding standard (with a few minor exceptions). Coding style is validated during PR build, where we inject an extra settings layer that promotes various suggestions to warning level. This ensures a high-quality codebase without interfering too much when editing code.
6060
You can run the following [PowerShell scripts](https://github.com/PowerShell/PowerShell/releases) locally:
61-
- `pwsh inspectcode.ps1`: Scans the code for style violations and opens the result in your web browser.
62-
- `pwsh cleanupcode.ps1`: Reformats the entire codebase to match with our configured style.
61+
- `pwsh ./inspectcode.ps1`: Scans the code for style violations and opens the result in your web browser.
62+
- `pwsh ./cleanupcode.ps1 [branch-name-or-commit-hash]`: Reformats the codebase to match with our configured style, optionally only changed files since the specified branch (usually master).
6363

6464
Code inspection violations can be addressed in several ways, depending on the situation:
6565
- Types that are reported to be never instantiated (because the IoC container creates them dynamically) should be decorated with `[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]`.

Build.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,21 @@ function RunCleanupCode {
4040
# When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
4141

4242
if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) {
43-
Write-Output "Running code cleanup on changed files in pull request"
44-
4543
# In the past, we used $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT for the merge commit hash. That is the pinned hash at the time the build is enqueued.
4644
# When a force-push happens after that, while the build hasn't yet started, this hash becomes invalid during the build, resulting in a lookup error.
47-
# To prevent failing the build for unobvious reasons we use HEAD, which is always the latest version.
48-
$mergeCommitHash = git rev-parse "HEAD"
49-
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
45+
# To prevent failing the build for unobvious reasons we use HEAD, which is always a detached head (the PR merge result).
46+
47+
$headCommitHash = git rev-parse HEAD
48+
CheckLastExitCode
5049

51-
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --disable-jb-path-hack --jb --profile='\"JADNC Full Cleanup\"' --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $mergeCommitHash -b $targetCommitHash --fail-on-diff --print-diff
50+
$baseCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
5251
CheckLastExitCode
52+
53+
if ($baseCommitHash -ne $headCommitHash) {
54+
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
55+
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
56+
CheckLastExitCode
57+
}
5358
}
5459
}
5560

Directory.Build.props

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
<AspNetVersion>6.0.*</AspNetVersion>
55
<EFCoreVersion>6.0.*</EFCoreVersion>
66
<EFCorePostgresVersion>6.0.*</EFCorePostgresVersion>
7-
<MicrosoftCodeAnalysisVersion>4.2.*</MicrosoftCodeAnalysisVersion>
7+
<MicrosoftCodeAnalysisVersion>4.3.*</MicrosoftCodeAnalysisVersion>
88
<HumanizerVersion>2.14.1</HumanizerVersion>
9-
<SwashbuckleVersion>6.2.*</SwashbuckleVersion>
10-
<JsonApiDotNetCoreVersionPrefix>5.0.3</JsonApiDotNetCoreVersionPrefix>
9+
<SwashbuckleVersion>6.4.*</SwashbuckleVersion>
10+
<NSwagApiClientVersion>13.16.*</NSwagApiClientVersion>
11+
<MicrosoftApiClientVersion>6.0.*</MicrosoftApiClientVersion>
12+
<NewtonsoftJsonVersion>13.0.*</NewtonsoftJsonVersion>
13+
<JsonApiDotNetCoreVersionPrefix>5.0.4</JsonApiDotNetCoreVersionPrefix>
1114
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
1215
<WarningLevel>9999</WarningLevel>
1316
<Nullable>enable</Nullable>
@@ -18,7 +21,7 @@
1821

1922
<ItemGroup>
2023
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" PrivateAssets="All" />
21-
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.1" PrivateAssets="All" />
24+
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.2" PrivateAssets="All" />
2225
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
2326
</ItemGroup>
2427

@@ -35,7 +38,7 @@
3538
<!-- Test Project Dependencies -->
3639
<PropertyGroup>
3740
<CoverletVersion>3.1.2</CoverletVersion>
38-
<MoqVersion>4.18.1</MoqVersion>
39-
<TestSdkVersion>17.2.0</TestSdkVersion>
41+
<MoqVersion>4.18.2</MoqVersion>
42+
<TestSdkVersion>17.3.1</TestSdkVersion>
4043
</PropertyGroup>
4144
</Project>

JsonApiDotNetCore.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
5757
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceUsingStatementBraces/@EntryIndexedValue">WARNING</s:String>
5858
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceWhileStatementBraces/@EntryIndexedValue">WARNING</s:String>
5959
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EventNeverSubscribedTo_002ELocal/@EntryIndexedValue">WARNING</s:String>
60+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LambdaExpressionMustBeStatic/@EntryIndexedValue">WARNING</s:String>
6061
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalizableElement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
6162
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">HINT</s:String>
6263
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeInternal/@EntryIndexedValue">SUGGESTION</s:String>

benchmarks/Benchmarks.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
5+
<ServerGarbageCollection>true</ServerGarbageCollection>
56
</PropertyGroup>
67

78
<ItemGroup>
89
<ProjectReference Include="..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
910
</ItemGroup>
1011

1112
<ItemGroup>
12-
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
13-
<PackageReference Include="Moq" Version="$(MoqVersion)" />
13+
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion)" PrivateAssets="all">
15+
<!-- This reference solely exists to prevent build warnings for conflicting versions of Microsoft.CodeAnalysis. -->
16+
</PackageReference>
1417
</ItemGroup>
1518
</Project>

benchmarks/Deserialization/OperationsDeserializationBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Benchmarks.Deserialization;
88

99
[MarkdownExporter]
10+
[MemoryDiagnoser]
1011
// ReSharper disable once ClassCanBeSealed.Global
1112
public class OperationsDeserializationBenchmarks : DeserializationBenchmarkBase
1213
{

benchmarks/Deserialization/ResourceDeserializationBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Benchmarks.Deserialization;
88

99
[MarkdownExporter]
10+
[MemoryDiagnoser]
1011
// ReSharper disable once ClassCanBeSealed.Global
1112
public class ResourceDeserializationBenchmarks : DeserializationBenchmarkBase
1213
{

benchmarks/QueryString/QueryStringParserBenchmarks.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System.ComponentModel.Design;
22
using BenchmarkDotNet.Attributes;
3+
using Benchmarks.Tools;
34
using JsonApiDotNetCore;
45
using JsonApiDotNetCore.Configuration;
56
using JsonApiDotNetCore.Middleware;
67
using JsonApiDotNetCore.QueryStrings;
78
using JsonApiDotNetCore.QueryStrings.Internal;
89
using JsonApiDotNetCore.Resources;
9-
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.WebUtilities;
1110
using Microsoft.Extensions.Logging.Abstractions;
1211

1312
namespace Benchmarks.QueryString;
@@ -71,31 +70,9 @@ public void DescendingSort()
7170
[Benchmark]
7271
public void ComplexQuery()
7372
{
74-
Run(100, () =>
75-
{
76-
const string queryString =
77-
"?filter[alt-attr-name]=abc,eq:abc&sort=-alt-attr-name&include=child&page[size]=1&fields[alt-resource-name]=alt-attr-name";
78-
79-
_queryStringAccessor.SetQueryString(queryString);
80-
_queryStringReader.ReadAll(null);
81-
});
82-
}
83-
84-
private void Run(int iterations, Action action)
85-
{
86-
for (int index = 0; index < iterations; index++)
87-
{
88-
action();
89-
}
90-
}
91-
92-
private sealed class FakeRequestQueryStringAccessor : IRequestQueryStringAccessor
93-
{
94-
public IQueryCollection Query { get; private set; } = new QueryCollection();
73+
const string queryString = "?filter[alt-attr-name]=abc,eq:abc&sort=-alt-attr-name&include=child&page[size]=1&fields[alt-resource-name]=alt-attr-name";
9574

96-
public void SetQueryString(string queryString)
97-
{
98-
Query = new QueryCollection(QueryHelpers.ParseQuery(queryString));
99-
}
75+
_queryStringAccessor.SetQueryString(queryString);
76+
_queryStringReader.ReadAll(null);
10077
}
10178
}

benchmarks/Serialization/OperationsSerializationBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Benchmarks.Serialization;
1010

1111
[MarkdownExporter]
12+
[MemoryDiagnoser]
1213
// ReSharper disable once ClassCanBeSealed.Global
1314
public class OperationsSerializationBenchmarks : SerializationBenchmarkBase
1415
{

benchmarks/Serialization/ResourceSerializationBenchmarks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Benchmarks.Serialization;
1313

1414
[MarkdownExporter]
15+
[MemoryDiagnoser]
1516
// ReSharper disable once ClassCanBeSealed.Global
1617
public class ResourceSerializationBenchmarks : SerializationBenchmarkBase
1718
{
Lines changed: 3 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using System.Collections.Immutable;
21
using System.Text.Json;
32
using System.Text.Json.Serialization;
3+
using Benchmarks.Tools;
44
using JetBrains.Annotations;
55
using JsonApiDotNetCore.Configuration;
66
using JsonApiDotNetCore.Middleware;
77
using JsonApiDotNetCore.Queries;
8-
using JsonApiDotNetCore.Queries.Expressions;
98
using JsonApiDotNetCore.Queries.Internal;
10-
using JsonApiDotNetCore.QueryStrings;
119
using JsonApiDotNetCore.Resources;
1210
using JsonApiDotNetCore.Resources.Annotations;
13-
using JsonApiDotNetCore.Serialization.Objects;
1411
using JsonApiDotNetCore.Serialization.Response;
15-
using Microsoft.AspNetCore.Http;
1612
using Microsoft.Extensions.Logging.Abstractions;
1713

1814
namespace Benchmarks.Serialization;
@@ -45,9 +41,9 @@ protected SerializationBenchmarkBase()
4541
// ReSharper restore VirtualMemberCallInConstructor
4642

4743
var linkBuilder = new FakeLinkBuilder();
48-
var metaBuilder = new FakeMetaBuilder();
44+
var metaBuilder = new NoMetaBuilder();
4945
IQueryConstraintProvider[] constraintProviders = Array.Empty<IQueryConstraintProvider>();
50-
var resourceDefinitionAccessor = new FakeResourceDefinitionAccessor();
46+
var resourceDefinitionAccessor = new NeverResourceDefinitionAccessor();
5147
var sparseFieldSetCache = new SparseFieldSetCache(constraintProviders, resourceDefinitionAccessor);
5248
var requestQueryStringAccessor = new FakeRequestQueryStringAccessor();
5349

@@ -122,141 +118,4 @@ public sealed class OutgoingResource : Identifiable<int>
122118
[HasMany]
123119
public ISet<OutgoingResource> Multi5 { get; set; } = null!;
124120
}
125-
126-
private sealed class FakeResourceDefinitionAccessor : IResourceDefinitionAccessor
127-
{
128-
public IImmutableSet<IncludeElementExpression> OnApplyIncludes(ResourceType resourceType, IImmutableSet<IncludeElementExpression> existingIncludes)
129-
{
130-
return existingIncludes;
131-
}
132-
133-
public FilterExpression? OnApplyFilter(ResourceType resourceType, FilterExpression? existingFilter)
134-
{
135-
return existingFilter;
136-
}
137-
138-
public SortExpression? OnApplySort(ResourceType resourceType, SortExpression? existingSort)
139-
{
140-
return existingSort;
141-
}
142-
143-
public PaginationExpression? OnApplyPagination(ResourceType resourceType, PaginationExpression? existingPagination)
144-
{
145-
return existingPagination;
146-
}
147-
148-
public SparseFieldSetExpression? OnApplySparseFieldSet(ResourceType resourceType, SparseFieldSetExpression? existingSparseFieldSet)
149-
{
150-
return existingSparseFieldSet;
151-
}
152-
153-
public object? GetQueryableHandlerForQueryStringParameter(Type resourceClrType, string parameterName)
154-
{
155-
return null;
156-
}
157-
158-
public IDictionary<string, object?>? GetMeta(ResourceType resourceType, IIdentifiable resourceInstance)
159-
{
160-
return null;
161-
}
162-
163-
public Task OnPrepareWriteAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken)
164-
where TResource : class, IIdentifiable
165-
{
166-
return Task.CompletedTask;
167-
}
168-
169-
public Task<IIdentifiable?> OnSetToOneRelationshipAsync<TResource>(TResource leftResource, HasOneAttribute hasOneRelationship,
170-
IIdentifiable? rightResourceId, WriteOperationKind writeOperation, CancellationToken cancellationToken)
171-
where TResource : class, IIdentifiable
172-
{
173-
return Task.FromResult(rightResourceId);
174-
}
175-
176-
public Task OnSetToManyRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds,
177-
WriteOperationKind writeOperation, CancellationToken cancellationToken)
178-
where TResource : class, IIdentifiable
179-
{
180-
return Task.CompletedTask;
181-
}
182-
183-
public Task OnAddToRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds,
184-
CancellationToken cancellationToken)
185-
where TResource : class, IIdentifiable
186-
{
187-
return Task.CompletedTask;
188-
}
189-
190-
public Task OnRemoveFromRelationshipAsync<TResource>(TResource leftResource, HasManyAttribute hasManyRelationship, ISet<IIdentifiable> rightResourceIds,
191-
CancellationToken cancellationToken)
192-
where TResource : class, IIdentifiable
193-
{
194-
return Task.CompletedTask;
195-
}
196-
197-
public Task OnWritingAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken)
198-
where TResource : class, IIdentifiable
199-
{
200-
return Task.CompletedTask;
201-
}
202-
203-
public Task OnWriteSucceededAsync<TResource>(TResource resource, WriteOperationKind writeOperation, CancellationToken cancellationToken)
204-
where TResource : class, IIdentifiable
205-
{
206-
return Task.CompletedTask;
207-
}
208-
209-
public void OnDeserialize(IIdentifiable resource)
210-
{
211-
}
212-
213-
public void OnSerialize(IIdentifiable resource)
214-
{
215-
}
216-
}
217-
218-
private sealed class FakeLinkBuilder : ILinkBuilder
219-
{
220-
public TopLevelLinks GetTopLevelLinks()
221-
{
222-
return new TopLevelLinks
223-
{
224-
Self = "TopLevel:Self"
225-
};
226-
}
227-
228-
public ResourceLinks GetResourceLinks(ResourceType resourceType, IIdentifiable resource)
229-
{
230-
return new ResourceLinks
231-
{
232-
Self = "Resource:Self"
233-
};
234-
}
235-
236-
public RelationshipLinks GetRelationshipLinks(RelationshipAttribute relationship, IIdentifiable leftResource)
237-
{
238-
return new RelationshipLinks
239-
{
240-
Self = "Relationship:Self",
241-
Related = "Relationship:Related"
242-
};
243-
}
244-
}
245-
246-
private sealed class FakeMetaBuilder : IMetaBuilder
247-
{
248-
public void Add(IDictionary<string, object?> values)
249-
{
250-
}
251-
252-
public IDictionary<string, object?>? Build()
253-
{
254-
return null;
255-
}
256-
}
257-
258-
private sealed class FakeRequestQueryStringAccessor : IRequestQueryStringAccessor
259-
{
260-
public IQueryCollection Query { get; } = new QueryCollection(0);
261-
}
262121
}

0 commit comments

Comments
 (0)