Skip to content

Commit 21ff29d

Browse files
authored
Merge branch 'openapi' into 1367-include-http-headers
2 parents 0d321c4 + 69d91d6 commit 21ff29d

13 files changed

+54
-47
lines changed

.config/dotnet-tools.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"jetbrains.resharper.globaltools": {
6-
"version": "2023.3.2",
6+
"version": "2023.3.3",
77
"commands": [
88
"jb"
99
]
@@ -15,7 +15,7 @@
1515
]
1616
},
1717
"dotnet-reportgenerator-globaltool": {
18-
"version": "5.2.0",
18+
"version": "5.2.1",
1919
"commands": [
2020
"reportgenerator"
2121
]

.github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ jobs:
138138
dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true"
139139
- name: Upload coverage to codecov.io
140140
if: matrix.os == 'ubuntu-latest'
141-
uses: codecov/codecov-action@v3
141+
env:
142+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
143+
uses: codecov/codecov-action@v4
142144
with:
143145
fail_ci_if_error: true
144146
verbose: true

.github/workflows/deps-review.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
- name: 'Checkout Repository'
1212
uses: actions/checkout@v4
1313
- name: 'Dependency Review'
14-
uses: actions/dependency-review-action@v3
14+
uses: actions/dependency-review-action@v4

JsonApiDotNetCore.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
6363
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ExtractCommonPropertyPattern/@EntryIndexedValue">SUGGESTION</s:String>
6464
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=IntroduceOptionalParameters_002EGlobal/@EntryIndexedValue">HINT</s:String>
6565
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LambdaExpressionMustBeStatic/@EntryIndexedValue">WARNING</s:String>
66+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalFunctionCanBeMadeStatic/@EntryIndexedValue">SUGGESTION</s:String>
6667
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalizableElement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
6768
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">HINT</s:String>
6869
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeInternal/@EntryIndexedValue">SUGGESTION</s:String>

ROADMAP.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
This document provides an overview of the direction this project is heading and lists what we intend to work on in the near future.
44

5-
> Disclaimer: This is an open source project. The available time of our contributors varies and therefore we do not plan release dates. This document expresses our current intent, which may change over time.
5+
> Disclaimer: This is an open-source project. The available time of our contributors varies and therefore we do not plan release dates. This document expresses our current intent, which may change over time.
66
7-
We have interest in the following topics. It's too soon yet to decide whether they'll make it into v5.x or in a later major version.
7+
We have an interest in the following topics. It's too soon yet to decide whether they'll make it into v5.x or in a later major version.
88

9+
- OpenAPI (Swagger): Generate documentation and typed clients [#1046](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1046)
10+
- Query strings on JSON-mapped columns [#1439](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1439)
11+
- Improved SQL Server support [#1118](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1118)
912
- Optimistic concurrency [#1119](https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/1119)
10-
- OpenAPI (Swagger) [#1046](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/1046)
1113
- Fluent API [#776](https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/776)
1214
- Idempotency [#1132](https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/1132)
1315

@@ -19,3 +21,5 @@ Please give us feedback that will give us insight on the following points:
1921
* Existing features that are missing some capability or otherwise don't work well enough.
2022
* Missing features that should be added to the product.
2123
* Design choices for a feature that is currently in-progress.
24+
25+
Please consider to [sponsor the project](https://github.com/sponsors/json-api-dotnet).

docs/usage/writing/updating.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
To modify the attributes of a single resource, send a PATCH request. The next example changes the article caption:
66

77
```http
8-
PATCH /articles HTTP/1.1
8+
PATCH /articles/1 HTTP/1.1
99
1010
{
1111
"data": {

src/JsonApiDotNetCore/Queries/QueryableBuilding/SelectClauseBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ private Expression CreateLambdaBodyInitializerForTypeHierarchy(FieldSelection se
9393
private static BinaryExpression CreateRuntimeTypeCheck(LambdaScope lambdaScope, Type concreteClrType)
9494
{
9595
// Emitting "resource.GetType() == typeof(Article)" instead of "resource is Article" so we don't need to check for most-derived
96-
// types first. This way, we can fallback to "anything else" at the end without worrying about order.
96+
// types first. This way, we can fall back to "anything else" at the end without worrying about order.
9797

98-
Expression concreteTypeConstant = concreteClrType.CreateTupleAccessExpressionForConstant(typeof(Type));
98+
Expression concreteTypeConstant = SystemExpressionBuilder.CloseOver(concreteClrType);
9999
MethodCallExpression getTypeCall = Expression.Call(lambdaScope.Accessor, TypeGetTypeMethod);
100100

101101
return Expression.MakeBinary(ExpressionType.Equal, getTypeCall, concreteTypeConstant, false, TypeOpEqualityMethod);

src/JsonApiDotNetCore/Queries/QueryableBuilding/SkipTakeClauseBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override Expression VisitPagination(PaginationExpression expression, Quer
3636

3737
private static Expression ExtensionMethodCall(Expression source, string operationName, int value, QueryClauseBuilderContext context)
3838
{
39-
Expression constant = value.CreateTupleAccessExpressionForConstant(typeof(int));
39+
Expression constant = SystemExpressionBuilder.CloseOver(value);
4040

4141
return Expression.Call(context.ExtensionType, operationName, [context.LambdaScope.Parameter.Type], source, constant);
4242
}

src/JsonApiDotNetCore/Queries/QueryableBuilding/WhereClauseBuilder.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ public override Expression VisitNullConstant(NullConstantExpression expression,
245245

246246
public override Expression VisitLiteralConstant(LiteralConstantExpression expression, QueryClauseBuilderContext context)
247247
{
248-
Type type = expression.TypedValue.GetType();
249-
return expression.TypedValue.CreateTupleAccessExpressionForConstant(type);
248+
return SystemExpressionBuilder.CloseOver(expression.TypedValue);
250249
}
251250
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Linq.Expressions;
2+
using System.Reflection;
3+
4+
#pragma warning disable AV1008
5+
6+
namespace JsonApiDotNetCore.Queries;
7+
8+
internal static class SystemExpressionBuilder
9+
{
10+
private static readonly MethodInfo CloseOverOpenMethod =
11+
typeof(SystemExpressionBuilder).GetMethods().Single(method => method is { Name: nameof(CloseOver), IsGenericMethod: true });
12+
13+
// To enable efficient query plan caching, inline constants (that vary per request) should be converted into query parameters.
14+
// https://stackoverflow.com/questions/54075758/building-a-parameterized-entityframework-core-expression
15+
//
16+
// CloseOver can be used to change a query like:
17+
// SELECT ... FROM ... WHERE x."Age" = 3
18+
// into:
19+
// SELECT ... FROM ... WHERE x."Age" = @p0
20+
21+
public static Expression CloseOver(object value)
22+
{
23+
ArgumentGuard.NotNull(value);
24+
25+
MethodInfo closeOverClosedMethod = CloseOverOpenMethod.MakeGenericMethod(value.GetType());
26+
return (Expression)closeOverClosedMethod.Invoke(null, [value])!;
27+
}
28+
29+
public static Expression CloseOver<T>(T value)
30+
{
31+
// From https://github.com/dotnet/efcore/issues/28151#issuecomment-1374480257.
32+
return ((Expression<Func<T>>)(() => value)).Body;
33+
}
34+
}

src/JsonApiDotNetCore/Queries/SystemExpressionExtensions.cs

-33
This file was deleted.

src/JsonApiDotNetCore/Resources/ResourceFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public NewExpression CreateNewExpression(Type resourceClrType)
102102
{
103103
object constructorArgument = ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, constructorParameter.ParameterType);
104104

105-
Expression argumentExpression = constructorArgument.CreateTupleAccessExpressionForConstant(constructorArgument.GetType());
105+
Expression argumentExpression = SystemExpressionBuilder.CloseOver(constructorArgument);
106106
constructorArguments.Add(argumentExpression);
107107
}
108108
#pragma warning disable AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException

0 commit comments

Comments
 (0)