Skip to content

Commit

Permalink
Merge branch 'openapi' into 1367-include-http-headers
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g authored Feb 21, 2024
2 parents 0d321c4 + 69d91d6 commit 21ff29d
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2023.3.2",
"version": "2023.3.3",
"commands": [
"jb"
]
Expand All @@ -15,7 +15,7 @@
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.2.0",
"version": "5.2.1",
"commands": [
"reportgenerator"
]
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ jobs:
dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true"
- name: Upload coverage to codecov.io
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deps-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
uses: actions/dependency-review-action@v4
1 change: 1 addition & 0 deletions JsonApiDotNetCore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$);</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ExtractCommonPropertyPattern/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=IntroduceOptionalParameters_002EGlobal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LambdaExpressionMustBeStatic/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalFunctionCanBeMadeStatic/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LocalizableElement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBePartlyConvertedToQuery/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeInternal/@EntryIndexedValue">SUGGESTION</s:String>
Expand Down
10 changes: 7 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

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

> 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.
> 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.
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.
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.

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

Expand All @@ -19,3 +21,5 @@ Please give us feedback that will give us insight on the following points:
* Existing features that are missing some capability or otherwise don't work well enough.
* Missing features that should be added to the product.
* Design choices for a feature that is currently in-progress.

Please consider to [sponsor the project](https://github.com/sponsors/json-api-dotnet).
2 changes: 1 addition & 1 deletion docs/usage/writing/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
To modify the attributes of a single resource, send a PATCH request. The next example changes the article caption:

```http
PATCH /articles HTTP/1.1
PATCH /articles/1 HTTP/1.1
{
"data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ private Expression CreateLambdaBodyInitializerForTypeHierarchy(FieldSelection se
private static BinaryExpression CreateRuntimeTypeCheck(LambdaScope lambdaScope, Type concreteClrType)
{
// Emitting "resource.GetType() == typeof(Article)" instead of "resource is Article" so we don't need to check for most-derived
// types first. This way, we can fallback to "anything else" at the end without worrying about order.
// types first. This way, we can fall back to "anything else" at the end without worrying about order.

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

return Expression.MakeBinary(ExpressionType.Equal, getTypeCall, concreteTypeConstant, false, TypeOpEqualityMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override Expression VisitPagination(PaginationExpression expression, Quer

private static Expression ExtensionMethodCall(Expression source, string operationName, int value, QueryClauseBuilderContext context)
{
Expression constant = value.CreateTupleAccessExpressionForConstant(typeof(int));
Expression constant = SystemExpressionBuilder.CloseOver(value);

return Expression.Call(context.ExtensionType, operationName, [context.LambdaScope.Parameter.Type], source, constant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ public override Expression VisitNullConstant(NullConstantExpression expression,

public override Expression VisitLiteralConstant(LiteralConstantExpression expression, QueryClauseBuilderContext context)
{
Type type = expression.TypedValue.GetType();
return expression.TypedValue.CreateTupleAccessExpressionForConstant(type);
return SystemExpressionBuilder.CloseOver(expression.TypedValue);
}
}
34 changes: 34 additions & 0 deletions src/JsonApiDotNetCore/Queries/SystemExpressionBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Linq.Expressions;
using System.Reflection;

#pragma warning disable AV1008

namespace JsonApiDotNetCore.Queries;

internal static class SystemExpressionBuilder
{
private static readonly MethodInfo CloseOverOpenMethod =
typeof(SystemExpressionBuilder).GetMethods().Single(method => method is { Name: nameof(CloseOver), IsGenericMethod: true });

// To enable efficient query plan caching, inline constants (that vary per request) should be converted into query parameters.
// https://stackoverflow.com/questions/54075758/building-a-parameterized-entityframework-core-expression
//
// CloseOver can be used to change a query like:
// SELECT ... FROM ... WHERE x."Age" = 3
// into:
// SELECT ... FROM ... WHERE x."Age" = @p0

public static Expression CloseOver(object value)
{
ArgumentGuard.NotNull(value);

MethodInfo closeOverClosedMethod = CloseOverOpenMethod.MakeGenericMethod(value.GetType());
return (Expression)closeOverClosedMethod.Invoke(null, [value])!;
}

public static Expression CloseOver<T>(T value)
{
// From https://github.com/dotnet/efcore/issues/28151#issuecomment-1374480257.
return ((Expression<Func<T>>)(() => value)).Body;
}
}
33 changes: 0 additions & 33 deletions src/JsonApiDotNetCore/Queries/SystemExpressionExtensions.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Resources/ResourceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public NewExpression CreateNewExpression(Type resourceClrType)
{
object constructorArgument = ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, constructorParameter.ParameterType);

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

0 comments on commit 21ff29d

Please sign in to comment.