Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package-versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>9.0.*</AspNetCoreVersion>
<EntityFrameworkCoreVersion>9.0.*</EntityFrameworkCoreVersion>
<EntityFrameworkCorePomeloVersion>9.0.0-*</EntityFrameworkCorePomeloVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
Expand All @@ -50,6 +49,5 @@
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>8.0.*</AspNetCoreVersion>
<EntityFrameworkCoreVersion>8.0.*</EntityFrameworkCoreVersion>
<EntityFrameworkCorePomeloVersion>$(EntityFrameworkCoreVersion)</EntityFrameworkCorePomeloVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Examples/DapperExample/DapperExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(EntityFrameworkCoreVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EntityFrameworkCorePomeloVersion)" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EntityFrameworkCoreVersion)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public override SqlTreeNode VisitResourceFieldChain(ResourceFieldChainExpression
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
{
Title = "Sorting or filtering on the requested attribute is unavailable.",
Detail = $"Sorting or filtering on attribute '{attribute.PublicName}' is unavailable because it is unmapped."
Detail = $"Sorting or filtering on attribute '{attribute}' is unavailable because it is unmapped."
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ protected void AssertIsIdentifiable(object? resource)
return _publicName ?? (_property != null ? _property.Name : base.ToString());
}

public string ToFullString()
{
return $"{_type?.PublicName}:{ToString()}";
}

/// <inheritdoc />
public override bool Equals(object? obj)
{
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static void ValidateAttributesInDerivedType(ResourceType resourceType)
if (resourceType.FindAttributeByPublicName(attribute.PublicName) == null)
{
throw new InvalidConfigurationException(
$"Attribute '{attribute.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
$"Attribute '{attribute}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
}
}
}
Expand All @@ -142,7 +142,7 @@ private static void ValidateRelationshipsInDerivedType(ResourceType resourceType
if (resourceType.FindRelationshipByPublicName(relationship.PublicName) == null)
{
throw new InvalidConfigurationException(
$"Relationship '{relationship.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
$"Relationship '{relationship}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ private string InnerToString(bool toFullString)

builder.Append(Keywords.Any);
builder.Append('(');
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute);
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute.ToString());
builder.Append(',');
builder.Append(string.Join(",", Constants.Select(constant => toFullString ? constant.ToFullString() : constant.ToString()).OrderBy(value => value)));
builder.Append(string.Join(',', Constants.Select(constant => toFullString ? constant.ToFullString() : constant.ToString()).OrderBy(value => value)));
builder.Append(')');

return builder.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ private string InnerToString(bool toFullString)
var builder = new StringBuilder();
builder.Append(Keywords.Has);
builder.Append('(');
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection);
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection.ToString());

if (Filter != null)
{
builder.Append(',');
builder.Append(toFullString ? Filter.ToFullString() : Filter);
builder.Append(toFullString ? Filter.ToFullString() : Filter.ToString());
}

builder.Append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public override string ToFullString()
private string InnerToString(bool toFullString)
{
var builder = new StringBuilder();
builder.Append(toFullString ? $"{Relationship.LeftType.PublicName}:{Relationship.PublicName}" : Relationship.PublicName);
builder.Append(toFullString ? $"{Relationship.LeftType}:{Relationship}" : Relationship.ToString());

if (Children.Count > 0)
{
builder.Append('{');
builder.Append(string.Join(",", Children.Select(child => toFullString ? child.ToFullString() : child.ToString()).OrderBy(name => name)));
builder.Append(string.Join(',', Children.Select(child => toFullString ? child.ToFullString() : child.ToString()).OrderBy(name => name)));
builder.Append('}');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override string ToFullString()
private string InnerToString(bool toFullString)
{
IReadOnlyCollection<ResourceFieldChainExpression> chains = IncludeChainConverter.Instance.GetRelationshipChains(this);
return string.Join(",", chains.Select(field => toFullString ? field.ToFullString() : field.ToString()).Distinct().OrderBy(name => name));
return string.Join(',', chains.Select(field => toFullString ? field.ToFullString() : field.ToString()).Distinct().OrderBy(name => name));
}

public override bool Equals(object? obj)
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private string InnerToString(bool toFullString)

if (TargetToOneRelationship != null)
{
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship);
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship.ToString());
}

builder.Append(',');
Expand All @@ -80,7 +80,7 @@ private string InnerToString(bool toFullString)
if (Child != null)
{
builder.Append(',');
builder.Append(toFullString ? Child.ToFullString() : Child);
builder.Append(toFullString ? Child.ToFullString() : Child.ToString());
}

builder.Append(')');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private string InnerToString(bool toFullString)

builder.Append(Operator.ToString().Camelize());
builder.Append('(');
builder.Append(string.Join(",", Terms.Select(term => toFullString ? term.ToFullString() : term.ToString())));
builder.Append(string.Join(',', Terms.Select(term => toFullString ? term.ToFullString() : term.ToString())));
builder.Append(')');

return builder.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ private string InnerToString(bool toFullString)
builder.Append('(');

builder.Append(toFullString
? string.Join(",", TargetAttribute.ToFullString(), TextValue.ToFullString())
: string.Join(",", TargetAttribute, TextValue));
? string.Join(',', TargetAttribute.ToFullString(), TextValue.ToFullString())
: string.Join(',', TargetAttribute.ToString(), TextValue.ToString()));

builder.Append(')');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum

public override string ToString()
{
return string.Join(",", Elements.Select(element => element.ToString()));
return string.Join(',', Elements.Select(element => element.ToString()));
}

public override string ToFullString()
{
return string.Join(",", Elements.Select(element => element.ToFullString()));
return string.Join(',', Elements.Select(element => element.ToFullString()));
}

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum

public override string ToString()
{
return string.Join(".", Fields.Select(field => field.PublicName));
return string.Join('.', Fields.Select(field => field.ToString()));
}

public override string ToFullString()
{
return string.Join(".", Fields.Select(field => $"{field.Type.PublicName}:{field.PublicName}"));
return string.Join('.', Fields.Select(field => field.ToFullString()));
}

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private string InnerToString(bool toFullString)
builder.Append('-');
}

builder.Append(toFullString ? Target.ToFullString() : Target);
builder.Append(toFullString ? Target.ToFullString() : Target.ToString());

return builder.ToString();
}
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Queries/Expressions/SortExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum

public override string ToString()
{
return string.Join(",", Elements.Select(child => child.ToString()));
return string.Join(',', Elements.Select(child => child.ToString()));
}

public override string ToFullString()
{
return $"{string.Join(",", Elements.Select(child => child.ToFullString()))}{(IsAutoGenerated ? " (auto-generated)" : "")}";
return $"{string.Join(',', Elements.Select(child => child.ToFullString()))}{(IsAutoGenerated ? " (auto-generated)" : "")}";
}

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public override TResult Accept<TArgument, TResult>(QueryExpressionVisitor<TArgum

public override string ToString()
{
return string.Join(",", Fields.Select(field => field.PublicName).OrderBy(name => name));
return string.Join(',', Fields.Select(field => field.ToString()).OrderBy(name => name));
}

public override string ToFullString()
{
return string.Join(".", Fields.Select(field => $"{field.Type.PublicName}:{field.PublicName}").OrderBy(name => name));
return string.Join(',', Fields.Select(field => $"{field.ToFullString()}").OrderBy(name => name));
}

public override bool Equals(object? obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ private string InnerToString(bool toFullString)
builder.Append(',');
}

builder.Append(resourceType.PublicName);
builder.Append(resourceType);
builder.Append('(');
builder.Append(toFullString ? fieldSet.ToFullString() : fieldSet);
builder.Append(toFullString ? fieldSet.ToFullString() : fieldSet.ToString());
builder.Append(')');
}

Expand Down
23 changes: 17 additions & 6 deletions src/JsonApiDotNetCore/Queries/FieldSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,51 @@ public FieldSelectors GetOrCreateSelectors(ResourceType resourceType)
}

public override string ToString()
{
return InnerToString(false);
}

public string ToFullString()
{
return InnerToString(true);
}

private string InnerToString(bool toFullString)
{
var builder = new StringBuilder();

var writer = new IndentingStringWriter(builder);
WriteSelection(writer);
WriteSelection(writer, toFullString);

return builder.ToString();
}

internal void WriteSelection(IndentingStringWriter writer)
internal void WriteSelection(IndentingStringWriter writer, bool toFullString)
{
using (writer.Indent())
{
foreach (ResourceType type in GetResourceTypes())
{
writer.WriteLine($"{nameof(FieldSelectors)}<{type.ClrType.Name}>");
WriterSelectors(writer, type);
WriterSelectors(writer, toFullString, type);
}
}
}

private void WriterSelectors(IndentingStringWriter writer, ResourceType type)
private void WriterSelectors(IndentingStringWriter writer, bool toFullString, ResourceType type)
{
using (writer.Indent())
{
foreach ((ResourceFieldAttribute field, QueryLayer? nextLayer) in GetOrCreateSelectors(type))
{
if (nextLayer == null)
{
writer.WriteLine(field.ToString());
writer.WriteLine(toFullString ? field.ToFullString() : field.ToString());
}
else
{
nextLayer.WriteLayer(writer, $"{field.PublicName}: ");
string prefix = $"{(toFullString ? field.ToFullString() : field.ToString())}: ";
nextLayer.WriteLayer(writer, toFullString, prefix);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/JsonApiDotNetCore/Queries/Parsing/FilterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private static ResourceType ResolveDerivedType(ResourceType baseType, string der

if (derivedType == null)
{
throw new QueryParseException($"Resource type '{derivedTypeName}' does not exist or does not derive from '{baseType.PublicName}'.", position);
throw new QueryParseException($"Resource type '{derivedTypeName}' does not exist or does not derive from '{baseType}'.", position);
}

return derivedType;
Expand Down Expand Up @@ -571,7 +571,7 @@ protected override void ValidateField(ResourceFieldAttribute field, int position
if (field.IsFilterBlocked())
{
string kind = field is AttrAttribute ? "attribute" : "relationship";
throw new QueryParseException($"Filtering on {kind} '{field.PublicName}' is not allowed.", position);
throw new QueryParseException($"Filtering on {kind} '{field}' is not allowed.", position);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/Queries/Parsing/SortParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override void ValidateField(ResourceFieldAttribute field, int position

if (field is AttrAttribute attribute && !attribute.Capabilities.HasFlag(AttrCapabilities.AllowSort))
{
throw new QueryParseException($"Sorting on attribute '{attribute.PublicName}' is not allowed.", position);
throw new QueryParseException($"Sorting on attribute '{attribute}' is not allowed.", position);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected override void ValidateField(ResourceFieldAttribute field, int position
if (field.IsViewBlocked())
{
string kind = field is AttrAttribute ? "attribute" : "relationship";
throw new QueryParseException($"Retrieving the {kind} '{field.PublicName}' is not allowed.", position);
throw new QueryParseException($"Retrieving the {kind} '{field}' is not allowed.", position);
}
}
}
24 changes: 17 additions & 7 deletions src/JsonApiDotNetCore/Queries/QueryLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,55 @@ public QueryLayer(ResourceType resourceType)
}

public override string ToString()
{
return InnerToString(false);
}

public string ToFullString()
{
return InnerToString(true);
}

private string InnerToString(bool toFullString)
{
var builder = new StringBuilder();

var writer = new IndentingStringWriter(builder);
WriteLayer(writer, null);
WriteLayer(writer, toFullString, null);

return builder.ToString();
}

internal void WriteLayer(IndentingStringWriter writer, string? prefix)
internal void WriteLayer(IndentingStringWriter writer, bool toFullString, string? prefix)
{
writer.WriteLine($"{prefix}{nameof(QueryLayer)}<{ResourceType.ClrType.Name}>");

using (writer.Indent())
{
if (Include is { Elements.Count: > 0 })
{
writer.WriteLine($"{nameof(Include)}: {Include}");
writer.WriteLine($"{nameof(Include)}: {(toFullString ? Include.ToFullString() : Include.ToString())}");
}

if (Filter != null)
{
writer.WriteLine($"{nameof(Filter)}: {Filter}");
writer.WriteLine($"{nameof(Filter)}: {(toFullString ? Filter.ToFullString() : Filter.ToString())}");
}

if (Sort != null)
{
writer.WriteLine($"{nameof(Sort)}: {Sort}");
writer.WriteLine($"{nameof(Sort)}: {(toFullString ? Sort.ToFullString() : Sort.ToString())}");
}

if (Pagination != null)
{
writer.WriteLine($"{nameof(Pagination)}: {Pagination}");
writer.WriteLine($"{nameof(Pagination)}: {(toFullString ? Pagination.ToFullString() : Pagination.ToString())}");
}

if (Selection is { IsEmpty: false })
{
writer.WriteLine(nameof(Selection));
Selection.WriteSelection(writer);
Selection.WriteSelection(writer, toFullString);
}
}
}
Expand Down
Loading
Loading