Closed
Description
DESCRIPTION
In my AuthorResourceDefinition
the OnApplyFilter method is overridden and adds a filter expression. When requesting a relationship, the OnApplyFilter()
of AuthorResourceDefinition gets called and adds the filter as expected. The ResourceFieldChainExpression however is applied on the secondary resource level. This fails, because the resource field name of the primary resource does not exist on the secondary one.
STEPS TO REPRODUCE
- In
AuthorResourceDefinition
overrideOnApplyFilter()
like shown at https://www.jsonapi.net/usage/extensibility/resource-definitions.html#change-filters:public override FilterExpression OnApplyFilter(FilterExpression existingFilter) { var isDeletedAttribute = ResourceType.Attributes.Single(author => author.Property.Name == nameof(Author.IsDeleted)); var isNotDeleted = new ComparisonExpression(ComparisonOperator.Equals, new ResourceFieldChainExpression(isDeletedAttribute), new LiteralConstantExpression(bool.FalseString)); return existingFilter == null ? (FilterExpression) isNotDeleted : new LogicalExpression(LogicalOperator.And, new[] { isNotDeleted, existingFilter }); }
- Send GET request to
/authors/1/relationships/books
EXPECTED BEHAVIOR
The request returns the books of author ID 1.
ACTUAL BEHAVIOR
The request returns an error:
{
"errors": [
{
"detail": "Type 'Book' does not contain a property named 'IsDeleted'.",
"id": "1",
"status": "500",
"title": "An unhandled error occurred while processing this request."
}
],
"links": {
"related": "/authors/1/books",
"self": "/authors/1/relationships/books"
},
"meta": {
"build": "dev",
"docs": "/swagger/index.html"
}
}
VERSIONS USED
- JsonApiDotNetCore version: 5.6.0
- ASP.NET Core version: 7.0.15
- Entity Framework Core version: 7.0.15
- Database provider: MS SQL