Skip to content

Commit 338c63e

Browse files
authored
Merge branch 'master' into harden-attributes
2 parents b51d681 + 5301d04 commit 338c63e

File tree

91 files changed

+3032
-491
lines changed

Some content is hidden

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

91 files changed

+3032
-491
lines changed

appveyor.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
image:
22
- Ubuntu2004
3-
# Downgrade to workaround error NETSDK1194 during 'dotnet pack': The "--output" option isn't supported when building a solution.
4-
# https://stackoverflow.com/questions/75453953/how-to-fix-github-actions-dotnet-publish-workflow-error-the-output-option-i
5-
- Previous Visual Studio 2022
3+
- Visual Studio 2022
64

75
version: '{build}'
86

@@ -34,7 +32,7 @@ for:
3432
-
3533
matrix:
3634
only:
37-
- image: Previous Visual Studio 2022
35+
- image: Visual Studio 2022
3836
services:
3937
- postgresql15
4038
install:
@@ -100,6 +98,9 @@ build_script:
10098
Write-Output ".NET version:"
10199
dotnet --version
102100
101+
Write-Output "PowerShell version:"
102+
pwsh --version
103+
103104
Write-Output "PostgreSQL version:"
104105
if ($IsWindows) {
105106
. "${env:ProgramFiles}\PostgreSQL\15\bin\psql" --version

benchmarks/Serialization/OperationsSerializationBenchmarks.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using BenchmarkDotNet.Attributes;
33
using JsonApiDotNetCore.Configuration;
44
using JsonApiDotNetCore.Middleware;
5+
using JsonApiDotNetCore.Queries;
56
using JsonApiDotNetCore.Queries.Internal;
67
using JsonApiDotNetCore.Resources;
78
using JsonApiDotNetCore.Serialization.Objects;
@@ -130,6 +131,6 @@ protected override JsonApiRequest CreateJsonApiRequest(IResourceGraph resourceGr
130131

131132
protected override IEvaluatedIncludeCache CreateEvaluatedIncludeCache(IResourceGraph resourceGraph)
132133
{
133-
return new EvaluatedIncludeCache();
134+
return new EvaluatedIncludeCache(Array.Empty<IQueryConstraintProvider>());
134135
}
135136
}

benchmarks/Serialization/ResourceSerializationBenchmarks.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using JsonApiDotNetCore;
55
using JsonApiDotNetCore.Configuration;
66
using JsonApiDotNetCore.Middleware;
7+
using JsonApiDotNetCore.Queries;
78
using JsonApiDotNetCore.Queries.Expressions;
89
using JsonApiDotNetCore.Queries.Internal;
910
using JsonApiDotNetCore.Resources.Annotations;
@@ -121,12 +122,12 @@ protected override JsonApiRequest CreateJsonApiRequest(IResourceGraph resourceGr
121122

122123
protected override IEvaluatedIncludeCache CreateEvaluatedIncludeCache(IResourceGraph resourceGraph)
123124
{
124-
ResourceType resourceAType = resourceGraph.GetResourceType<OutgoingResource>();
125+
ResourceType resourceType = resourceGraph.GetResourceType<OutgoingResource>();
125126

126-
RelationshipAttribute single2 = resourceAType.GetRelationshipByPropertyName(nameof(OutgoingResource.Single2));
127-
RelationshipAttribute single3 = resourceAType.GetRelationshipByPropertyName(nameof(OutgoingResource.Single3));
128-
RelationshipAttribute multi4 = resourceAType.GetRelationshipByPropertyName(nameof(OutgoingResource.Multi4));
129-
RelationshipAttribute multi5 = resourceAType.GetRelationshipByPropertyName(nameof(OutgoingResource.Multi5));
127+
RelationshipAttribute single2 = resourceType.GetRelationshipByPropertyName(nameof(OutgoingResource.Single2));
128+
RelationshipAttribute single3 = resourceType.GetRelationshipByPropertyName(nameof(OutgoingResource.Single3));
129+
RelationshipAttribute multi4 = resourceType.GetRelationshipByPropertyName(nameof(OutgoingResource.Multi4));
130+
RelationshipAttribute multi5 = resourceType.GetRelationshipByPropertyName(nameof(OutgoingResource.Multi5));
130131

131132
var include = new IncludeExpression(new HashSet<IncludeElementExpression>
132133
{
@@ -142,7 +143,7 @@ protected override IEvaluatedIncludeCache CreateEvaluatedIncludeCache(IResourceG
142143
}.ToImmutableHashSet())
143144
}.ToImmutableHashSet());
144145

145-
var cache = new EvaluatedIncludeCache();
146+
var cache = new EvaluatedIncludeCache(Array.Empty<IQueryConstraintProvider>());
146147
cache.Set(include);
147148
return cache;
148149
}

docs/build-dev.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 7.0
1+
#Requires -Version 7.3
22

33
# This script builds the documentation website, starts a web server and opens the site in your browser. Intended for local development.
44

docs/generate-examples.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 7.0
1+
#Requires -Version 7.3
22

33
# This script generates response documents for ./request-examples
44

docs/getting-started/faq.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,24 @@ Here are some injectable request-scoped types to be aware of:
133133
- `IJsonApiRequest`: This contains routing information, such as whether a primary, secondary, or relationship endpoint is being accessed.
134134
- `ITargetedFields`: Lists the attributes and relationships from an incoming POST/PATCH resource request. Any fields missing there should not be stored (partial updates).
135135
- `IEnumerable<IQueryConstraintProvider>`: Provides access to the parsed query string parameters.
136-
- `IEvaluatedIncludeCache`: This tells the response serializer which related resources to render, which you need to populate.
137-
- `ISparseFieldSetCache`: This tells the response serializer which fields to render in the attributes and relationship objects. You need to populate this as well.
136+
- `IEvaluatedIncludeCache`: This tells the response serializer which related resources to render.
137+
- `ISparseFieldSetCache`: This tells the response serializer which fields to render in the `attributes` and `relationships` objects.
138138

139-
You may also want to inject the singletons `IJsonApiOptions` (which contains settings such as default page size) and `IResourceGraph` (the JSON:API model of resources and relationships).
139+
You may also want to inject the singletons `IJsonApiOptions` (which contains settings such as default page size) and `IResourceGraph` (the JSON:API model of resources, attributes and relationships).
140140

141141
So, back to the topic of where to intercept. It helps to familiarize yourself with the [execution pipeline](~/internals/queries.md).
142142
Replacing at the service level is the simplest. But it means you'll need to read the parsed query string parameters and invoke
143143
all resource definition callbacks yourself. And you won't get change detection (HTTP 203 Not Modified).
144144
Take a look at [JsonApiResourceService](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/src/JsonApiDotNetCore/Services/JsonApiResourceService.cs) to see what you're missing out on.
145145

146-
You'll get a lot more out of the box if replacing at the repository level instead. You don't need to apply options, analyze query strings or populate caches for the serializer.
146+
You'll get a lot more out of the box if replacing at the repository level instead. You don't need to apply options or analyze query strings.
147147
And most resource definition callbacks are handled.
148148
That's because the built-in resource service translates all JSON:API aspects of the request into a database-agnostic data structure called `QueryLayer`.
149149
Now the hard part for you becomes reading that data structure and producing data access calls from that.
150150
If your data store provides a LINQ provider, you may reuse most of [QueryableBuilder](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/src/JsonApiDotNetCore/Queries/Internal/QueryableBuilding/QueryableBuilder.cs),
151151
which drives the translation into [System.Linq.Expressions](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/).
152-
Note however, that it also produces calls to `.Include("")`, which is an Entity Framework Core-specific extension method, so you'll likely need to prevent that from happening.
153-
We use this for accessing [MongoDB](https://github.com/json-api-dotnet/JsonApiDotNetCore.MongoDb/blob/674889e037334e3f376550178ce12d0842d7560c/src/JsonApiDotNetCore.MongoDb/Queries/Internal/QueryableBuilding/MongoQueryableBuilder.cs).
152+
Note however, that it also produces calls to `.Include("")`, which is an Entity Framework Core-specific extension method, so you'll likely need to prevent that from happening. There's an example [here](https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/master/src/Examples/NoEntityFrameworkExample/Repositories/InMemoryResourceRepository.cs).
153+
We use a similar approach for accessing [MongoDB](https://github.com/json-api-dotnet/JsonApiDotNetCore.MongoDb/blob/674889e037334e3f376550178ce12d0842d7560c/src/JsonApiDotNetCore.MongoDb/Queries/Internal/QueryableBuilding/MongoQueryableBuilder.cs).
154154

155155
> [!TIP]
156156
> [ExpressionTreeVisualizer](https://github.com/zspitz/ExpressionTreeVisualizer) is very helpful in trying to debug LINQ expression trees!

docs/internals/queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Processing a request involves the following steps:
2929
To get a sense of what this all looks like, let's look at an example query string:
3030

3131
```
32-
/api/v1/blogs?
32+
/api/blogs?
3333
include=owner,posts.comments.author&
3434
filter=has(posts)&
3535
sort=count(posts)&
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#Requires -Version 7.3
2+
13
curl -s -f http://localhost:14141/api/books
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#Requires -Version 7.3
2+
13
curl -s -f http://localhost:14141/api/people/1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#Requires -Version 7.3
2+
13
curl -s -f http://localhost:14141/api/books?include=author

0 commit comments

Comments
 (0)